While architecting enterprise RAG applications at Softuvo, our engineering team ran into latency bottlenecks and high token costs when retrieving and re-ranking complex multi-document contexts.
To solve this, we benchmarked several retrieval and chunking strategies within LangChain to strike the right balance between answer accuracy and execution speed.
Key Optimization Strategies We Applied:
Parent-Document Retriever: Using smaller child chunks (200 tokens) for vector similarity search, but fetching larger parent document chunks (1000 tokens) for LLM context generation.
Contextual Compression & Re-Ranking: Integrating Cohere / Flashrank re-rankers post-retrieval to drop low-relevance documents before passing the prompt to the model, reducing context token usage by ~35%.
Async Vector Store Queries: Leveraging parallel retriever calls across multiple vector indexes for multi-tenant querying.
Minimal Code Example:
Python
from langchain.retrievers import ParentDocumentRetriever
from langchain.storage import InMemoryStore
from langchain_community.vectorstores import Chroma
from langchain_text_splitters import RecursiveCharacterTextSplitter
# Parent and child chunking setup
child_splitter = RecursiveCharacterTextSplitter(chunk_size=200, chunk_overlap=20)
parent_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
vectorstore = Chroma(collection_name="docs", embedding_function=embeddings)
store = InMemoryStore()
retriever = ParentDocumentRetriever(
vectorstore=vectorstore,
docstore=store,
child_splitter=child_splitter,
parent_splitter=parent_splitter,
)
We’d love to hear from other devs building in production: What chunking ratios or re-ranking models have given you the best trade-off between retrieval quality and LLM latency?
The expensive part of that parent-child setup is usually the expansion, not the vector search. Re-rank the small child hits first, then expand only the top few into their parent text. If you expand first and re-rank after, three children from the same section become the same long block three times, and you pay those tokens before you drop the junk.
Cap unique parents, not just the child count. Keep the parent text in the same store as the children, keyed by the parent id already stored on the child metadata, so the second lookup is one batched fetch. An in-memory doc store in front of a persisted vector index disappears on restart and turns every cold process into a full re-index.
Are you checking whether compression preserves every fact needed to answer the question, alongside the token reduction?
We tested a tuned hybrid pipeline with temporal filters, semantic retrieval, rank fusion and reranking. Its remaining misses omitted required supporting proof.
I’m behind Jylus, which handles evidence preparation natively before the answer model runs. We published that comparison here:
Your multi-document workload looks relevant. Is evidence completeness still causing problems after the optimisations, or have you mainly got latency left to solve?
Great breakdown of production trade-offs. Two additional architectural levers that consistently cut P95 RAG latency by 40-55% and prompt token overhead by ~35% in LangChain/LangGraph pipelines when combining Parent-Document retrieval with cross-encoder reranking:
A common bottleneck with ParentDocumentRetriever + Cross-Encoder reranking is passing the expanded 1,500-2,000 token parent documents into the cross-encoder (bge-reranker-large / Cohere Rerank). Because cross-encoder self-attention scales quadratically with sequence length, reranking 20 parent chunks adds 350-600 ms of GPU latency.
Fix: Run your hybrid (BM25 + Dense RRF) recall and Cross-Encoder reranking strictly on the child chunks (256-384 tokens), keep only the top $K=4..6$ winning child chunks, and resolve/deduplicate their parent_id payloads from your InMemoryStore / RedisStoreafter the reranker finishes.
Instead of injecting the entire parent document verbatim when two child chunks hit the same parent, extract a ±2 sentence window around each matched child span and merge overlapping spans:
from langchain_core.documents import Document
def deduplicate_parent_windows(scored_children: list[tuple[Document, float]], max_parents: int = 5) -> list[Document]:
seen_parents: dict[str, Document] = {}
for doc, score in sorted(scored_children, key=lambda x: x[1], reverse=True):
pid = str(doc.metadata.get("parent_id") or doc.metadata.get("source_id") or id(doc))
if pid not in seen_parents:
seen_parents[pid] = doc
if len(seen_parents) >= max_parents:
break
return list(seen_parents.values())