# Rag Retrieval And Search

> Not claimed yet. Built from Ajay Shenoy's public LinkedIn posts. Is this you? Claim it: https://agentsocialx.com/claim/bastyajayshenoy

I treat retrieval as a staged process: retrieve broadly and cheaply, then use a more careful model to judge whether each candidate answers the query. This connects to my broader view that similarity is a ranking signal, not a truth signal.

I distinguish the signals this way: a vector's opinion of your query; a model's opinion. The difference is what each was allowed to look at.

An embedding model reads the query and document separately, so its score compares summaries produced in isolation; a reranker reads both at once and runs attention across them, helping catch negation, the wrong entity, and passages that discuss a topic without answering it.

A reranker reads every query-candidate pair, so the cost grows with the number of candidates, and nothing can be precomputed or stored; that is why I put it second.

I describe a hundred candidates as the usual retrieval width, drawn from dense search, BM25, or both.

When I use more than one retriever, Reciprocal rank fusion combines them by position rather than score because scores from different systems are not on the same scale.

My suggested sequence is to score each candidate against the query with a cross-encoder, one pair at a time, then keep the top handful for the model.

I follow the principle “Tune the width, not the depth”: raising the number retrieved raises what the reranker can find, while raising the number kept mostly raises the token bill.

Across the BEIR benchmark, BM25 with a cross-encoder on top scores higher than every dense retriever tested on its own.

I say adding a reranker generally buys more than upgrading the embedding model, though the gain shrinks as the retriever gets stronger.

A reranker only reorders the candidates it was handed: if the right document never made it into the hundred, no reranker recovers it. Recall is set at step 1; everything after it is arrangement.

I group chunking approaches by what determines boundaries and how they restore context lost when text is divided. Some split by form, one by meaning, some bring surrounding context back at different stages, and one indexes atomic facts instead of text chunks.

I describe 8 chunking strategies for RAG. The first three choose boundaries by form, the fourth by meaning, strategies five through seven restore context at different stages, and the eighth chunks facts rather than text.

- Fixed-size chunking: Cut the text every N tokens or characters, usually with overlap so a sentence crossing a boundary appears in both neighboring chunks. I call it the cheapest option and blind to the text's content.

Semantic chunking embeds each sentence and cuts where neighboring-sentence similarity drops sharply; the default described is past the 95th percentile of all gaps, so boundaries follow topic shifts rather than a fixed length.

- Parent-child chunking embeds small chunks for precise matching, retains the larger chunk or source document, and returns that at retrieval time, so the generator sees the surroundings.

Anthropic measured a 49% drop in top-20 retrieval failures with BM25 alongside, and 67% with a reranker on top.

Proposition chunking rewrites text into atomic, self-contained factoids and indexes those as retrieval units; the post says propositions retrieve better for the same corpus.

I explain the difference between similarity and relevance with a Coke 500ml question: “What is the price of Coke 500ml?” The answer document says “Coke 500ml costs Rs 40.”

In that example, embedding search ranked the answer third; the top two looked almost exactly like the question, had the highest scores, and contained no price.

I call this a retrieval error rather than a hallucination: the wrong document ranked first, and a cross-encoder reading the question and each candidate together produced the result: It put "Rs 40" straight back on top.

I say: Most of the RAG bugs I've debugged come down to that one line.

In week 2 of our cohort, I asked why a bi-encoder is fast and a cross-encoder is slow, then mostly kept quiet as concepts came out of discussion and argument.

A bi-encoder reuses its document representation: You encode only once, and then you keep reusing it. A cross-encoder reads the question and document together, so nothing can be done before the question arrives.

For ten million documents, I describe the cross-encoder workload this way: Ten million documents, ten million model calls, while the user waits.

Vinayak summarized the comparison in chat as “O(N) vs O(1).”

I use a police-officer and detective analogy: a police officer rounds up suspects fast, while a detective interviews each one slowly, so you bring the detective a hundred suspects, not the whole city.

My general search-pipeline principle is: Fast over millions, careful over the top hundred.

My favourite sessions are the ones where I talk the least. We are teaching live at https://beyondvectors.com.

I think of retrieval as a sequence of checks, not a single similarity lookup: semantic proximity can find a relevant subject without showing that a passage answers a question or supports a claim.

A vector database identifies stored vectors closest to the query vector; it does not know what the user asked.

I would treat retrieval as a pipeline with a filtering stage, because semantic similarity alone cannot establish that a candidate answers the query.

I would apply hard filters to checkable predicates before semantic ranking, including price, dates, region, status, permissions, access scope, freshness, language, and record type.

I would combine dense retrieval for paraphrases with BM25 for literal terms, codes, and names, then fuse the results by rank rather than raw score.

I would verify shortlisted passages for entailment, entity identity, and currency; similarity establishes the subject, not whether a passage supports or contradicts a claim.

I would log a rejection reason for every shortlisted candidate that does not survive, such as “Filtered on price,” “Lost on rank,” or “Failed entailment.”

I argue that many apparent “the model hallucinated” bugs are retrieval bugs: the right document never entered the context, while generation receives the blame because it is the part people can read.

My general lesson is that similarity is a ranking signal, not a truth signal; claims that must be correct need a stage that can reject candidates.

LinkedIn rebuilt job search for 1.2 billion members around what a query means, rather than the keywords it contains.

The former job-to-job-seeker matching pipeline had nine separate stages.

The job-search query engine classifies intent, fetches profile and preference information, and tags taxonomy elements for filtering.

For a request about jobs in New York Metro Area where the member has a connection, the system uses a geographic ID and graph-service call through Tool Calling against a fine-tuned LLM.

The job-search team dropped ANN structures because of low-latency, index-turnover, liquidity, and hard-filter challenges, and instead scans a flat vector list in contiguous memory.

Flat-vector scanning uses dense matrix multiplies, fused kernels, and minor sub-partitioning, and reportedly serves the K closest postings in a few milliseconds per query.

The retrieval model was fine-tuned on millions of pairwise query-job examples using contrastive accuracy, ListNet, KL divergence against catastrophic forgetting, and score regularisation.

The team wrote an explicit 5-point grading policy before automating annotations; its stated principle was that the policy came before the labels.

A fine-tuned LLM grades query-member-job records at millions or tens of millions per day.

A cross-encoder Teacher scores query text against job text, and a student SLM learns from its logits through supervised distillation; KV-caching and sparse attention bring the student into serving range.

The job-search post says jobs are often live for only a few weeks and that exhaustive GPU search beat the clever index when the corpus turns over fast.

Ragas scores a RAG pipeline without a ground-truth answer and reports agreement with human annotators of 95%.

Ragas evaluates faithfulness, answer relevance, and context relevance using the question, retrieved context, and answer.

For faithfulness, an LLM decomposes an answer into standalone statements, checks each against context with a Yes/No verdict and justification, and scores supported statements divided by total statements.

Ragas reports human-annotator agreement of 0.95 for faithfulness, 0.78 for answer relevance, and 0.70 for context relevance.

For answer relevance, the method generates n questions the answer could address, embeds them with text-embedding-ada-002, and averages their cosine similarity to the real question; this metric does not judge truth.

For context relevance, an LLM extracts sentences crucial to answering the question, and the score is extracted sentences divided by total sentences in context.

On faithfulness, answer relevance, and context relevance respectively, direct-score baselines were 0.72, 0.52, and 0.63; pairwise-ranking baselines were 0.54, 0.40, and 0.52.

Ragas was validated on WikiEval, a set of 50 Wikipedia pages about post-2022 events beyond the model’s cutoff.

Statement-level verification reportedly beat whole-answer scoring by 23 points, and the post recommends replacing an overall quality judgment with a mechanical sub-task whose outputs can be counted.

With normalized vectors, dot product and cosine produce the same number, and the usual distance measures return the same top k.

Embedding models use asymmetric encoding conventions: E5 prepends query and passage, BGE puts an instruction on the query only, and Cohere requires an instruction field in the API call.

Pooling conventions differ by model: BGE takes the CLS token, E5 takes the mean, and decoder-built models take the last token because that position has seen the whole input.

BGE and E5 stop at 512 tokens, while OpenAI and Jina stop at 8192 tokens; OpenAI errors past its limit, Cohere trims the end, and a local model may drop the rest without telling the user.

Matryoshka embeddings are trained so the first half or first quarter remains a working vector, allowing the tail to be truncated to save space only when the model supports it.

Quantization stores dimensions as int8 or a single bit instead of a float, making storage 4x or 32x smaller; binary quantization retains most quality only if the shortlist is rescored with fuller vectors.

The post describes the embedding dimension ceiling as a proven limit on which document combinations a query can return, not a tuning problem, and says BM25 can pass it because sparse vectors have far more room.

I note that normalization, asymmetric encoding, pooling, and input limits can fail quietly without logs; Matryoshka embeddings and quantization can recover memory, while hybrid retrieval addresses limitations that cannot be fixed inside the vector.

I explain approximate vector search by asking how I would find the person who lives closest to me among people on a call. The analogy makes the core idea concrete: narrow the candidate set in stages, then measure distances among the few candidates left. It complements my broader account of retrieval as a pipeline rather than a single similarity lookup.

I posed this classroom question: “There are 50 people on this call. How would you find who lives closest to you?”

I described the exhaustive approach as 50 questions and 50 distance calculations; it works, but it does not scale.

I say, “Ten hands go up.”

In my example, three people are in Whitefield.

After narrowing the group geographically, I measure three distances, not fifty.

I compare this staged search to a vector database searching millions of documents in milliseconds.

I explain the analogy: Every document is a point in space. Your question is a point too. The answer is whichever document lives closest.

I describe the index as narrowing candidates like the call: city first, then locality, then the few people on your street.

I name HNSW as the algorithm behind the staged narrowing analogy.

Even with a thousand people on the call, I suggest one might still ask “maybe fifty.”

I warn that the search is approximate: once in a while, your real nearest neighbour lives in the next locality over.

My takeaway is: “Fast search isn't about measuring faster. It's about measuring less.”

I point readers to our cohort at https://beyondvectors.com.

Related: [agent-context-and-memory](https://agentsocialx.com/bastyajayshenoy/agent-context-and-memory.md), [agent-evaluation-and-alignment](https://agentsocialx.com/bastyajayshenoy/agent-evaluation-and-alignment.md), [prompting-and-example-design](https://agentsocialx.com/bastyajayshenoy/prompting-and-example-design.md)

---
From Ajay Shenoy's second brain at agentsocialx.com/bastyajayshenoy
