Prompt
I'm building a chatbot that needs vector retrieval with metadata filters
Latest observation
Nov 1, 2026
OpenAI APIWeb search: off
A good pattern is:
-
Chunk your documents
- Split into semantically useful chunks.
- Keep chunk size consistent enough for retrieval.
-
Attach metadata to each chunk
- Examples:
source,author,date,tenant_id,product,language,access_level,doc_type. - Store metadata alongside the embedding.
- Examples:
-
Index vectors in a vector database
- Use a store that supports similarity search + metadata filtering.
- Common choices: Pinecone, Weaviate, Milvus, Qdrant, Elasticsearch/OpenSearch vector fields, pgvector.
-
At query time
- Convert the user query to an embedding.
- Apply metadata filters before or during similarity search.
- Retrieve top-k chunks.
- Optionally re-rank results for better quality.
Example filter use cases
- “Only search documents from tenant A”
- “Only return docs updated after 2024-01-01”
- “Only search policy documents”
- “Only search English content”
Example metadata schema
{
"doc_id": "abc123",
"chunk_id": "abc123_04",
"source": "hr_handbook.pdf",
"tenant_id": "tenant_42",
"doc_type": "policy",
"language": "en",
"created_at": "2025-01-12",
"access_level": "employee"
}
Example query flow
- User asks: “What is our remote work policy?”
- Detect context/constraints:
tenant_id = tenant_42doc_type = policylanguage = en
- Run vector search with filters:
- embedding(query)
- filter metadata
- return top 5 relevant chunks
- Feed retrieved chunks into the LLM for answer generation.
Practical tips
- Filter first when possible to reduce search space.
- Keep metadata values normalized (
"en"not"English"sometimes and"EN"elsewhere). - Use indexed fields for frequently filtered metadata.
- Avoid overly restrictive filters that cause zero results.
- If access control matters, enforce filters server-side, not in the client.
- Consider hybrid retrieval: keyword + vector + metadata filters.
If you want a simple stack
- Embedding model: OpenAI embeddings or similar
- Vector DB: Qdrant / Pinecone / Weaviate / pgvector
- RAG orchestration: LangChain or LlamaIndex
If you want, I can give you:
- a code example in Python,
- a schema design for metadata,
- or a recommended architecture for your chatbot.