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_kbounds the result size;score_thresholddrops 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:
metric | Operator | Distance 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
| Store | Processor | Use when |
|---|---|---|
| Qdrant | vector_search | You want server-side score thresholds and payload filtering. |
| PostgreSQL + pgvector | pgvector_search | Your vectors live next to relational data; one database to operate. |
| Milvus | milvus_search | Large collections with Milvus already deployed. |
Verify
- Run ingestion on a tiny document set.
- Run the search config with a query that paraphrases one document; the expected match appears first with a clearly better score than the rest.
- Run a nonsense query; with a threshold set, expect an empty (not failed) result.
Failure modes
| Symptom | Cause | Fix |
|---|---|---|
| Every query returns the same top hit | Queries not embedded, or wrong field | Confirm the embedding processor ran before the search. |
| Scores look wrong after a model change | Query and ingestion used different models | Re-ingest or switch back; never mix models across halves. |
Batch fails to error_output | Null/empty query vector or SQL error | Check the input column; pgvector search does not retry. |