enhanced_parent_self_query_retrieverΒΆ

Enhanced MCP Retriever combining Parent Document Retriever with Self-Query.

This implementation combines: 1. Parent-child document retrieval for context preservation 2. Self-query metadata filtering for natural language queries 3. Metadata propagation from parent to child chunks

The key insight: Store metadata on BOTH parent docs AND child chunks, enabling self-query filtering on chunks while returning full parents.

ClassesΒΆ

EnhancedMCPRetriever

Enhanced retriever that combines parent-child documents with self-query.

FunctionsΒΆ

main()

Run the enhanced retriever example.

Module ContentsΒΆ

class enhanced_parent_self_query_retriever.EnhancedMCPRetriever(engine: haive.core.engine.aug_llm.AugLLMConfig)ΒΆ

Enhanced retriever that combines parent-child documents with self-query.

The trick: Create a custom retriever that: 1. Uses self-query to filter child chunks by metadata 2. Returns parent documents for matching chunks 3. Maintains all metadata relationships

create_self_query_retriever(k: int = 5) langchain.retrievers.self_query.base.SelfQueryRetrieverΒΆ

Create a self-query retriever that works with parent documents.

async demonstrate_queries() NoneΒΆ

Demonstrate various query patterns.

async find_and_analyze_best_server(requirements: str) langchain_core.documents.Document | NoneΒΆ

Find the best server matching requirements using enhanced retrieval.

async query_with_parent_context(query: str, k: int = 5) list[langchain_core.documents.Document]ΒΆ

Query using self-query on chunks but return full parent documents.

This is the key method that combines both approaches!

async setup_enhanced_retriever() NoneΒΆ

Set up the enhanced parent-child retriever with self-query.

child_vectorstore = NoneΒΆ
doc_loaderΒΆ
engineΒΆ
metadata_fields = []ΒΆ
parent_retriever = NoneΒΆ
parent_storeΒΆ
async enhanced_parent_self_query_retriever.main()ΒΆ

Run the enhanced retriever example.