Prompt
How do I search across text embeddings with metadata filters?
Latest observation
Nov 14, 2026
OpenAI APIWeb search: off
To search across text embeddings with metadata filters, you typically combine:
- Vector similarity search over embeddings
- Structured filtering over metadata fields
Basic idea
Each document/chunk is stored with:
- an embedding vector for semantic search
- metadata like:
authordatesourcecategorytenant_idtags
A query does two things:
- computes the query embedding
- searches for nearest vectors only among records matching the filter
Common search pattern
Example query:
“Find docs about refund policy, but only from
supportcategory and after2024-01-01.”
Conceptually:
WHERE category = 'support'
AND created_at >= '2024-01-01'
ORDER BY embedding_distance(query_embedding, embedding)
LIMIT 10
In practice
1) Store embeddings + metadata
Each record might look like:
{
"id": "doc_123",
"text": "Refunds are available within 30 days...",
"embedding": [0.12, -0.44, ...],
"metadata": {
"category": "support",
"author": "alice",
"created_at": "2024-05-10",
"tenant_id": "acme"
}
}
2) Build the query embedding
Convert the user query into a vector using the same embedding model used for documents.
3) Apply metadata filter
Use exact-match / range / boolean filters depending on your database.
4) Run vector similarity search
Search only the filtered subset, or search first and then filter if your system requires it.
Example with a vector database
Pinecone-style filter
{
"vector": [0.21, -0.08, ...],
"topK": 5,
"filter": {
"category": { "$eq": "support" },
"created_at": { "$gte": "2024-01-01" }
}
}
Weaviate-style concept
{
"nearVector": { "vector": [0.21, -0.08, ...] },
"where": {
"operator": "And",
"operands": [
{
"path": ["category"],
"operator": "Equal",
"valueText": "support"
}
]
}
}
SQL + vector extension example
If using PostgreSQL with pgvector:
SELECT id, text
FROM documents
WHERE metadata->>'category' = 'support'
AND (metadata->>'created_at')::date >= '2024-01-01'
ORDER BY embedding <-> :query_embedding
LIMIT 10;
Filter types you can use
Usually supported:
- Equality:
category = "support" - Contains / IN:
tag in ["billing", "refund"] - Range: dates, numbers
- Boolean:
is_public = true - Compound logic: AND / OR / NOT
Best practices
- Filter first, then vector search if the database supports it efficiently.
- Use indexed metadata fields for performance.
- Keep metadata normalized and consistent.
- Store timestamps as proper date/time types, not strings, when possible.
- If the filter is very selective, it can significantly speed up search.
- If your vector DB doesn’t support filters well, you may need:
- pre-filtering in SQL
- post-filtering after ANN search
- separate indexes per tenant/category
Example workflow
User asks:
“Show me finance-related notes from last week about taxes.”
You would:
- Embed the query
- Filter metadata:
department = "finance"created_at >= last_week_startcreated_at <= last_week_end
- Run similarity search on the remaining vectors
- Return top results
If you want, I can also show:
- a LangChain example
- a pgvector example
- Pinecone / Weaviate / Milvus examples
- a schema design for embedding + metadata search