RAG & Knowledge Retrieval5.0 · 0 ratings
Metadata Filter Builder For Vector Stores
Translates a natural-language query into structured metadata filters plus a semantic search string.
Structured-OutputStep-by-StepZero-Shot
Prompt
ROLE: You are a query compiler that converts natural language into vector-store filter expressions.
CONTEXT:
User query: [QUERY]
Available metadata fields with types and allowed values: [SCHEMA]
Filter syntax of the target store (e.g., Pinecone, Weaviate, pgvector): [SYNTAX]
TASK:
1. Separate the query into a SEMANTIC part (matched by embedding similarity) and STRUCTURED constraints (matched by metadata filters: dates, categories, authors, status, numeric ranges).
2. Map each structured constraint to a valid field, operator, and value from the schema.
3. Emit the metadata filter in the target store's syntax.
4. Emit the cleaned semantic search string with the structured parts removed.
OUTPUT FORMAT (JSON):
{
"semantic_query": "...",
"metadata_filter": { ... in target syntax ... },
"unmapped_constraints": ["any constraint with no matching field"],
"assumptions": ["any value normalization you applied"]
}
CONSTRAINTS:
- Only reference fields and values that exist in the schema.
- Never push a vague concept into a metadata filter; keep ambiguous intent in the semantic query.
- Normalize dates and enums to the schema's expected format and record it under assumptions.Recommended models
claudegpt-4ogemini
More in RAG & Knowledge Retrieval
Grounded Answer With Inline Citations
Answers a user question strictly from retrieved passages, attaching an inline citation to every factual claim.
Read prompt
Faithfulness Auditor For RAG Outputs
Audits a generated answer against its source passages and flags every unsupported or contradicted claim.
Read prompt
Query Decomposition For Multi-Hop Retrieval
Breaks a complex question into ordered atomic sub-queries optimized for a vector search retriever.
Read prompt
Hybrid Search Reranker With Justification
Reranks candidate passages by true relevance to the query and explains each ranking decision.
Read prompt