Most teams build their first retrieval system the same way: slice every document into fixed 512-token chunks, push them into a vector database, and hope the embedding model does the hard work. That hope gets you through a demo. It does not survive contact with real users.
In production, a legal contract falls apart when you sever a liability clause from its exceptions. API documentation turns useless when a code sample gets detached from its function signature. A customer support thread becomes noise when you rip a single complaint out of its conversational history. The problem is rarely the language model sitting at the end of the pipeline. The problem is what you feed it.
We learned this the hard way. Our initial retrieval layer looked standard but behaved inconsistently. So we rebuilt it around a simple idea: treat retrieval as measured infrastructure, not magic. Here is exactly what changed, and how we pushed recall to 95 percent while cutting the 95th-percentile latency from 850 ms to 320 ms.
The Fixed-Chunk Trap
Uniform token counts are easy to code and easy to explain. That convenience masks a basic truth: documents have structure. When you ignore that structure, you destroy signal.
Consider a ten-page master service agreement. A fixed 512-token slice will land mid-obligation, splitting a clause from the very cap table that limits it. The retrieval step then returns half a thought. The generator hallucinates the rest. In API documentation, a chunk that is too large dilutes the embedding with boilerplate headers, burying the specific method a developer needs. In support tickets, a fixed window treats a conversation as a bag of sentences, stripping away the back-and-forth that reveals what actually failed.
We stopped treating chunk size as a hyperparameter we guessed. We started treating it as a mapping exercise between the document type and the information architecture inside it.
Match Your Chunking to the Data
The fix is not one perfect chunk size. The fix is three distinct strategies tuned to three distinct data shapes.
Legal documents now go through recursive splitting. The algorithm first looks for the largest natural boundaries—sections, then subsections, then numbered clauses—and only falls back to smaller splits when necessary. This keeps a termination clause attached to its survival conditions. The retrieval step sees complete logical units, which sharply reduces the model’s temptation to invent missing exceptions.
API and code documentation get structure-aware chunking. Markdown headers, code fences, and parameter tables are parsed as atomic units. We do not split inside a code block. We keep docstrings adjacent to their signatures. The result is that a query for a specific class method retrieves the full context a developer needs: the description, the typed parameters, and the working example.
Support and conversational data use semantic chunking. Instead of counting tokens, we look for shifts in topic or intent. If a customer describes a bug in message three and pastes a stack trace in message seven, we chunk by meaning, not by message index. The retrieval layer then returns the full arc of the problem rather than a orphaned sentence.
Why Vector Search Alone Fails
Even perfect chunks die in a pure vector search. Dense embeddings excel at capturing meaning and synonymy, but they are notoriously fuzzy on exact strings. If an engineer searches for the precise error code ERR_CONNECTION_REFUSED, vector similarity might return a dozen conceptual neighbors and miss the exact match buried at rank fourteen.
Keyword search with BM25 has the opposite problem. It finds exact tokens but misses semantic intent. A user asking “why is my database down” will never match a document that says “troubleshooting connection timeouts.”
We now run both. Vector and keyword results are fed into Reciprocal Rank Fusion, which blends the two ranked lists without requiring calibrated scores. The fused list is then passed through a cross-encoder reranker. The reranker is slower than the initial retrieval, but it is far more precise because it judges query-document relevance directly rather than through compressed embeddings. That hybrid pipeline alone lifted our recall by 15 percent.
Fixing Bad Queries Before They Hit the Index
వినియోగదారులు ఆదర్శవంతమైన సెర్చ్ క్వెరీలను (search queries) రాయరు. వారు అసంపూర్తిగా ఉన్న లాగ్ లైన్లను (log lines) పేస్ట్ చేస్తారు. "ఇది పనిచేయడం లేదు" అని టైప్ చేస్తారు. మీ డాక్యుమెంటేషన్లో ఎప్పుడూ లేని సాంకేతిక పదజాలాన్ని (jargon) ఉపయోగిస్తారు. మీరు ముడి క్వెరీని (raw query) నమ్మితే, మీరు కేవలం శబ్దాన్ని (noise) మాత్రమే నమ్ముతున్నట్లు అవుతుంది.
మేము ఇప్పుడు ప్రతి వచ్చే క్వెరీని రిట్రీవల్ లేయర్కు (retrieval layer) పంపే ముందు మూడు నుండి ఐదు వైవిధ్యాలుగా (variations) విస్తరిస్తున్నాము. ఒక వైవిధ్యం నేరుగా పారాఫ్రేజ్ (paraphrase) కావచ్చు. మరొకటి ఒక ఊహాజనిత ఆదర్శ డాక్యుమెంట్ టైటిల్ కావచ్చు. మూడవది సంభాషణాత్మక పదాలను (conversational filler) తొలగించి, సాంకేతిక కీవర్డ్లను (technical keywords) మాత్రమే వేరు చేస్తుంది. ప్రతి వేరియంట్ను ఎంబెడ్ (embed) చేసి సెర్చ్ చేస్తాము. ఆ తర్వాత మేము అభ్యర్థనల సమూహాలను (candidate pools) డూప్లికేట్లను తొలగించి (deduplicate) విలీనం చేస్తాము.
ఇది ఉచితం కాదు. ఆ అదనపు ఎంబెడ్డింగ్ కాల్స్ (embedding calls) ఖర్చుతో కూడుకున్నవి మరియు కొన్ని మిల్లీసెకన్ల సమయాన్ని తీసుకుంటాయి. కానీ రికాల్ (recall) పై దీని ప్రభావం అద్భుతంగా ఉంది: క్వెరీలను విస్తరించడం ద్వారా మేము 78 శాతం నుండి 96 శాతానికి చేరుకున్నాము. మెరుగైన రిట్రీవల్ వల్ల జనరేషన్ విండో (generation window) తగ్గుతుంది మరియు మోడల్ సరైన సందర్భాన్ని (context) పొందుతుంది, దీనివల్ల చివరికి మేము డబ్బును ఆదా చేయగలిగాము. కొంచెం ఖరీదైన రిట్రీవల్ దశ, పొడవైన మరియు భ్రమలతో కూడిన (hallucinated) జనరేషన్ దశ కంటే చౌకైనది.
ఊహించడం ఆపండి. వెతకడం ప్రారంభించండి.
సరైన చంకింగ్ (chunking), హైబ్రిడ్ రిట్రీవల్ (hybrid retrieval) మరియు క్వెరీ విస్తరణను అమలు చేసిన తర్వాత కూడా, మేము ఒక సంక్లిష్టమైన సమస్యను (combinatorial mess) ఎదుర్కొన్నాము. చంక్ సైజ్ (chunk size), చంక్ ఓవర్ల్యాప్ (chunk overlap), top-k రిట్రీవల్ డెప్త్ (retrieval depth), reranker కటాఫ్స్ (reranker cutoffs) మరియు ఫ్యూజన్ వెయిట్స్ (fusion weights) అన్నీ ఒకదానితో ఒకటి ప్రభావితమవుతాయి. మాన్యువల్ గ్రిడ్ సెర్చ్ (manual grid search) చేయడానికి వారాల సమయం పట్టేది మరియు అది కూడా సరైన ఫలితాన్ని ఇవ్వకపోవచ్చు.
ఈ సమస్యను పరిష్కరించడానికి మేము బేసియన్ ఆప్టిమైజేషన్ (Bayesian optimization) వైపు మారాము. ప్రతి కాంబినేషన్ను విడదీసి పరీక్షించే బదులు, ఏ కాన్ఫిగరేషన్లు బాగా పనిచేయవచ్చో అల్గారిథమ్ అంచనా వేస్తూ, క్రమంగా ఉత్తమమైన ప్రాంతాలపై దృష్టి సారిస్తుంది.
దీని అవుట్పుట్ ఒకే ఒక పర్ఫెక్ట్ సెట్టింగ్ కాదు. ఇది ఎంపికల యొక్క పరేటో ఫ్రాంటియర్ (Pareto frontier). ఒక వైపు, మా హై-త్రూపుట్ API సపోర్ట్ ఎండ్పాయింట్ కోసం ఆప్టిమైజ్ చేయబడిన లీన్ కాన్ఫిగరేషన్ (lean configuration) ఉంది: వేగవంతమైన ఇన్ఫరెన్స్ (inference), మోడరేట్ రికాల్ మరియు అతి తక్కువ లాటెన్సీ (latency). మరోవైపు, లీగల్ రివ్యూ కోసం ఒక అగ్రెసివ్ కాన్ఫిగరేషన్ (aggressive configuration) ఉంది: లోతైన రిట్రీవల్, భారీ రీర్యాంకింగ్ మరియు ఎక్కువ ఓవర్ల్యాప్, అంటే వేగం కంటే ఖచ్చితత్వానికి ప్రాధాన్యత ఇస్తుంది. ఈ ఫ్రాంటియర్ స్పష్టంగా ఉండటం వల్ల, మేము "అన్నీ ఒకేలా సరిపోతాయి" (one size fits all) అని అనుకోకుండా, ఉత్పత్తికి తగిన పాయింట్ను ఎంచుకోగలుగుతున్నాము.
గణాంకాలు వాస్తవంగా ఎలా ఉన్నాయి
ఈ మార్పులు వ్యవస్థను ఒక బలహీనమైన ప్రోటోటైప్ నుండి కొలవదగిన ప్రొడక్షన్ పైప్లైన్గా మార్చాయి.
Recall at ten 78 శాతం నుండి 95 శాతానికి పెరిగింది. అంటే మా కార్పస్ (corpus) లో సరైన సమాధానం ఉన్నప్పుడు, ఇరవై సార్లు వెతికితే పందొమ్మిది సార్లు మేము దానిని కనుగొంటాము.
95th పెర్సంటైల్ వద్ద లాటెన్సీ (latency) 850 ms నుండి 320 ms కి తగ్గింది. హైబ్రిడ్ స్టాక్ చూడటానికి భారంగా అనిపించవచ్చు, కానీ స్మార్ట్ ఇండెక్సింగ్, చిన్న రీర్యాంకర్లు మరియు అవసరమైనప్పుడు మాత్రమే అగ్రెసివ్ చంక్స్ను అందించే సామర్థ్యం వల్ల మొత్తం వ్యవస్థ వేగవంతమైంది.
హాలూసినేషన్ రేటు (Hallucination rate)—దీనిని హోల్డ్-అవుట్ గోల్డెన్ డేటాసెట్ (held-out golden dataset) పై మానవ అనోటేటర్లు ట్రాక్ చేస్తారు—12 శాతం నుండి 3 శాతానికి తగ్గింది. మోడల్కు పూర్తి స్థాయి, సంబంధిత సందర్భం (context) లభించినప్పుడు, అది తప్పుడు సమాచారాన్ని సృష్టించడం ఆపివేస్తుంది.
క్వెరీకి అయ్యే ఖర్చు $0.008 నుండి $0.005 కి తగ్గింది. మెరుగైన రిట్రీవల్ అంటే చిన్నవి మరియు మరింత ఫోకస్డ్ LLM ప్రాంప్ట్లు మరియు తక్కువ రికవరీ ప్రయత్నాలు అని అర్థం. క్వెరీ విస్తరణ కోసం చేసే అదనపు ఎంబెడ్డింగ్ ఖర్చు, జనరేషన్ లో కలిగే ఆదా ముందు చాలా తక్కువ.
గోల్డెన్ డేటాసెట్ను నిర్మించండి మరియు రిట్రీవల్ను కోడ్ లాగా పరిగణించండి
మీరు దీని నుండి ఒక విషయం నేర్చుకోవాలనుకుంటే, అది కొలత యొక్క క్రమశిక్షణ (discipline of measurement) అయి ఉండాలి. మేము నిజమైన ప్రశ్నలు మరియు ధృవీకరించబడిన సమాధానాల స్థానాలతో ఒక చిన్న గోల్డెన్ డేటాసెట్ను (golden dataset) నిర్మించాము. ఏదైనా మార్పు ప్రొడక్షన్లోకి వెళ్లే ముందు, అది ఆ డేటాసెట్పై పరీక్షించబడుతుంది. రికాల్ మరియు లాటెన్సీలను రియల్ టైమ్లో పర్యవేక్షిస్తాము, కేవలం నోట్బుక్లో చూసి అంచనా వేయము.
రిట్రీవల్ అనేది కేవలం ఒక రీసెర్చ్ డెమో కాదు. అది ఒక ఇన్ఫ్రాస్ట్రక్చర్ (infrastructure). మీ స్టాక్ లోని మిగిలిన భాగాల మాదిరిగానే దీనికి కూడా యూనిట్ టెస్ట్లు (unit tests), రిగ్రెషన్ బెంచ్మార్క్లు (regression benchmarks) మరియు ఆటోమేటెడ్ ఆప్టిమైజేషన్ అవసరం. చంక్లను టోకెన్ల ఆధారంగా కాకుండా, డాక్యుమెంట్ స్ట్రక్చర్ ఆధారంగా విభజించండి. వెక్టర్ మరియు కీవర్డ్ సెర్చ్ను రీర్యాంకర్తో కలపండి. వినియోగదారులు నిజంగా రాసే క్వెరీలను విస్తరించండి. ఆపై మీ అంతర్ దృష్టి (intuition) కంటే సెర్చ్ అల్గారిథమ్ను కీలను సర్దుబాటు (tune the knobs) చేయడానికి అనుమతించండి.
మేము వివరించిన పైప్లైన్ కేవలం సిద్ధాంతపరమైనది కాదు. మీరు అసలు కథనాన్ని ఇక్కడ చదవవచ్చు, మరియు మీకు ఈ అంశాలపై ఆసక్తి ఉన్న కమ్యూనిటీతో రిట్రీవల్ ఇంజనీరింగ్ గురించి చర్చించాలనుకుంటే, GyaanSetu AI group అందుబాటులో ఉంది.
