Prompt

How do I search across text embeddings with metadata filters?

Artificial Intelligence / AI Search2 observationsLast seen Nov 14, 2026

Latest observation

Nov 14, 2026OpenAI APIWeb search: off

To search across text embeddings with metadata filters, you typically combine:

  1. Vector similarity search over embeddings
  2. Structured filtering over metadata fields

Basic idea

Each document/chunk is stored with:

  • an embedding vector for semantic search
  • metadata like:
    • author
    • date
    • source
    • category
    • tenant_id
    • tags

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 support category and after 2024-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:

  1. Embed the query
  2. Filter metadata:
    • department = "finance"
    • created_at >= last_week_start
    • created_at <= last_week_end
  3. Run similarity search on the remaining vectors
  4. 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

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.