Skip to main content
The metadata tags Deasy Labs extracts become retrieval filters for a RAG chatbot. A user can ask “answer using only Supplier Agreements” or “only documents governed by California law”, and the retriever narrows the candidate pool before the LLM sees a single chunk. Filtered retrieval keeps answers grounded in the right documents instead of the most superficially similar ones.

What You’ll Build

Prerequisites

  • A data connector with ingested and classified documents
  • Python 3.9+ with qdrant-client, fastembed, and openai installed

Step 1. Pull Chunk Text and File-Level Tags

Fetch each file’s tags with metadata.list_paginated, then the chunk text with data_source.list_ingested_data. Each chunk record carries its file’s tag values.

Step 2. Embed and Index with Tags as Payload

Every chunk goes into the vector index with its tag values attached as payload fields.

Step 3. Ask, with Optional Metadata Filters

The filter narrows the candidate pool before similarity search runs. Without it, retrieval considers every chunk in the corpus.

Step 4. Compare Filtered and Unfiltered Retrieval

Run the same question both ways and measure how the filter narrows the candidate pool. Pick a filter value that actually exists in your data.

Why Filtered Retrieval Wins

Any tag you extract becomes a filter for free. The richer your taxonomy, the more precisely users can scope questions.

How to Use This

  • Scope answers by any extracted tag. Pass filters={"governing_law": "California"} or any other tag/value pair.
  • Swap the corpus. Change CONNECTOR and FILTERABLE_TAGS; the pipeline adapts to whatever tags exist.
  • Productionize. Point at a persistent Qdrant cluster instead of :memory:, or skip the manual indexing entirely and use data_slice.export_vdb as in the Clean Up a RAG Index. If your tag names contain spaces, slugify them before using them as payload keys; some vector stores cannot filter on keys with spaces.

Next Steps

Clean Up a RAG Index

Use the platform’s own vector export instead of indexing manually.

Taxonomies and Tags

Design the tags that power your filters.

Keep Answers Current Over Time

Keep the chatbot answering from current documents only.

Data Quality Gate

Feed the index only documents that pass quality checks.