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.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Structured Output

Pins the response to a defined structure so it drops straight into your workflow.

Learn this technique
Step-by-Step

Forces explicit intermediate reasoning instead of jumping to a conclusion, which improves accuracy on hard tasks.

Learn this technique
Zero-Shot

Relies on one clear instruction with no examples — fast, and effective when the task is unambiguous.

Learn this technique

Recommended models

claudegpt-4ogemini

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in RAG & Knowledge Retrieval