🔍 Vector Search (pgvector)

Native PostgreSQL vector similarity search through GraphQL. 9+ distance operators, HNSW indexing, semantic search.

9+ Distance Operators via GraphQL

FraiseQL exposes all pgvector distance operators through type-safe GraphQL filters. Dense and sparse vectors, custom distance functions, and vector aggregations.

Operator GraphQL Filter Use Case Range
Dense Vectors
<=> cosine_distance cosineDistance Text similarity, recommendations 0.0 (identical) to 2.0 (opposite)
<-> l2_distance l2Distance Euclidean distance 0.0+ (smaller = more similar)
<+> l1_distance l1Distance Manhattan distance 0.0+ (smaller = more similar)
<#> inner_product innerProduct Negative inner product -∞ to 0.0 (larger = more similar)
<~> hamming_distance hammingDistance Binary vectors 0+ bits differ
<%> jaccard_distance jaccardDistance Set similarity 0.0 (identical) to 1.0 (no overlap)
Sparse Vectors
sparse_cosine_distance sparseCosineDistance Sparse text embeddings 0.0 to 2.0
sparse_l2_distance sparseL2Distance Sparse Euclidean distance 0.0+
sparse_inner_product sparseInnerProduct Sparse inner product -∞ to 0.0

GraphQL VectorFilter Schema

Type-safe vector filtering with automatic PostgreSQL query generation. No SQL injection, full type safety.

GraphQL Schema
input VectorFilter {
  # Dense vector operators
  cosineDistance: VectorDistanceFilter
  l2Distance: VectorDistanceFilter
  l1Distance: VectorDistanceFilter
  innerProduct: VectorDistanceFilter
  hammingDistance: VectorDistanceFilter
  jaccardDistance: VectorDistanceFilter

  # Sparse vector operators
  sparseCosineDistance: VectorDistanceFilter
  sparseL2Distance: VectorDistanceFilter
  sparseInnerProduct: VectorDistanceFilter

  # Additional functions
  customDistance: CustomDistanceFilter
  vectorNorm: VectorNormFilter
  quantizedDistance: QuantizedDistanceFilter
}

input VectorDistanceFilter {
  vector: [Float!]!
  threshold: Float
  limit: Int
}

Sub-millisecond Performance

HNSW

Hierarchical Navigable Small World

Industry-standard ANN indexing for billion-scale vector search with 99.9% recall.

IVFFlat

Inverted File Index

PostgreSQL's built-in IVF implementation for high-dimensional vector search.

< 0.5ms

Rust Pipeline

Vector filtering passes through FraiseQL's Rust pipeline for sub-millisecond processing.

Semantic Search Query

GraphQL Query
query SemanticSearch($embedding: [Float!]!) {
  products(
    filter: {
      descriptionEmbedding: {
        cosineDistance: {
          vector: $embedding
          threshold: 0.8
          limit: 10
        }
      }
    }
  ) {
    id
    name
    description
    similarity: _distance
  }
}
Generated PostgreSQL
SELECT
  id, name, description,
  1 - (embedding <=> $1) as _distance
FROM tb_product
WHERE embedding <=> $1 <= 0.8
ORDER BY embedding <=> $1
LIMIT 10;

Why pgvector in PostgreSQL?

✅ FraiseQL + pgvector

  • • Single PostgreSQL database
  • • ACID transactions with vectors
  • • GraphQL API included
  • • No sync overhead
  • • Cost-effective scaling
  • • Native JSONB + vectors

❌ External Vector DBs

  • • Separate vector database
  • • Complex sync architecture
  • • Additional GraphQL layer needed
  • • Higher operational cost
  • • Eventual consistency issues
  • • Multiple data stores

AI/ML Integrations

🤗

Hugging Face

Sentence transformers, CLIP embeddings, local inference

🟣

OpenAI

text-embedding-ada-002, GPT-4 integration patterns

🤖

Cohere

Embed API, multilingual embeddings, custom models

Ready to Build AI Applications?

Start with semantic search and RAG systems using PostgreSQL + GraphQL

Get Started with pgvector →