MultiVectorRetriever links precise retrieval representations to richer source documents. A vector store searches smaller child chunks, while a byte-backed document store returns the larger parent chunk for answer synthesis. section 8.4 section 8.4.2
Build the pattern by separating what is embedded from what is returned:
- Split source content into coarse parent chunks and smaller child chunks. section 8.4.2
- Assign each child chunk its parent identifier, embed the children in Chroma, and store parents in InMemoryByteStore. section 8.4.2
- Invoke the retriever with a query; it searches granular vectors but returns richer parent documents. section 8.4.2
- Experiment with summaries, hypothetical questions, or expanded neighboring chunks when ordinary embeddings miss useful matches or context. section 8.4.4 section 8.5
Cornwall Ranger query
A direct child-chunk search returns the concise ticket passage. MultiVectorRetriever returns a broader South Cornwall document containing transport details, the ticket information, and nearby attractions, giving synthesis more context. section 8.4.2 section 8.5
Listing 8.4 Parent and child splitters for MultiVectorRetriever
parent_splitter = RecursiveCharacterTextSplitter(
chunk_size=3000) #1
child_splitter = RecursiveCharacterTextSplitter(
chunk_size=500) #2
child_chunks_collection = Chroma( #3
collection_name="uk_child_chunks",
embedding_function=OpenAIEmbeddings(
openai_api_key=OPENAI_API_KEY),
)
child_chunks_collection.reset_collection() #4
doc_byte_store = InMemoryByteStore() #5
doc_key = "doc_id"
multi_vector_retriever = MultiVectorRetriever( #6
vectorstore=child_chunks_collection,
byte_store=doc_byte_store
)
Inspect the minimal configuration connecting child-chunk vectors, an in-memory byte store, and MultiVectorRetriever. section 8.4.2
