Skip to main content
Version: 0.7.x

Recipe: semantic search

Goal. Return the nearest stored passages for each incoming query without an LLM — the retrieval-only pattern behind search boxes, recommendation feeds, and duplicate detection.

Prerequisites. Documents already ingested (see vector RAG pipeline); an OpenAI-compatible embeddings endpoint with the same model used at ingestion.

Qdrant retrieval​

- type: embedding
api_base: "http://localhost:9997/v1"
model: "text-embedding-3-small"
api_key: "${env:EMBEDDING_API_KEY:-}"
field: "query"
- type: vector_search
url: "http://localhost:6333"
collection: documents
vector_field: embedding
top_k: 5
score_threshold: 0.75
target_field: matches
  • top_k bounds the result size; score_threshold drops weak matches at the store, so an empty result means "nothing similar enough", not "an error".
  • Matches arrive as a JSON array text column ({id, score, payload}), nearest first — feed it into SQL, JSON tooling, or a sink.
  • concurrency (default 4) bounds in-flight requests while preserving row order.

pgvector retrieval​

- type: embedding
api_base: "http://localhost:9997/v1"
model: "text-embedding-3-small"
api_key: "${env:EMBEDDING_API_KEY:-}"
field: "query"
- type: pgvector_search
url: "postgres://postgres:${env:PG_PASSWORD:-}@localhost:5432/vectors"
table: documents
metric: cosine
top_k: 5
target_field: matches

Distance semantics — filter on the raw distance, not a percentage:

metricOperatorDistance meaning
cosine<=>cosine distance; 0 = identical direction, range [0, 2]
l2<->Euclidean distance; 0 = identical
inner_product<#>negative inner product (smaller = more similar)

pgvector has no server-side threshold parameter: retrieve top_k and filter in SQL (WHERE distance <= 0.25 for a cosine-distance cutoff).

Complete runnable example​

The registered example examples/semantic_search_pgvector.yaml (manifest name semantic-search-pgvector) wires query embedding → pgvector_search → SQL projection → stdout.

Choosing the store​

StoreProcessorUse when
Qdrantvector_searchYou want server-side score thresholds and payload filtering.
PostgreSQL + pgvectorpgvector_searchYour vectors live next to relational data; one database to operate.
Milvusmilvus_searchLarge collections with Milvus already deployed.

Verify​

  1. Run ingestion on a tiny document set.
  2. Run the search config with a query that paraphrases one document; the expected match appears first with a clearly better score than the rest.
  3. Run a nonsense query; with a threshold set, expect an empty (not failed) result.

Failure modes​

SymptomCauseFix
Every query returns the same top hitQueries not embedded, or wrong fieldConfirm the embedding processor ran before the search.
Scores look wrong after a model changeQuery and ingestion used different modelsRe-ingest or switch back; never mix models across halves.
Batch fails to error_outputNull/empty query vector or SQL errorCheck the input column; pgvector search does not retry.