TECHNOLOGY

Elasticsearch passage retrieval: nested kNN and supporting inner hits

In this article
THE QUICK TAKE

Nested kNN ranks a parent by its best matching passage, and supporting inner hits identify the passage behind that score.

Elasticsearch nested passage retrieval should return the passage that produced a document’s match, not only the parent document. Without that supporting nested hit, a relevant-looking title can conceal that the chosen evidence comes from the wrong section, revision or conditional instruction inside a long document.

Understand parent and passage scoring

The official nested kNN guide describes vectors stored in nested sections and parent documents ranked by their best matching passage. Nested kNN supports max score mode. This differs from averaging all passages or returning an unrestricted list of independent chunks. Keep the parent-level selection policy visible when interpreting results, especially if several highly relevant passages belong to the same long manual.

Keep conditions in the correct nested scope

The nested query reference explains how nested objects match. Conditions intended to apply to one passage must be placed so they constrain the same relevant nested object. A parent can contain a current procedure and an obsolete appendix simultaneously. Matching current status somewhere in the document does not establish that the vector-matching passage itself belongs to the current procedure.

Test a misleading parent document

Create a manual containing a relevant obsolete passage and a less similar current passage. Query for the current procedure and inspect both the parent hit and its supporting nested evidence. Then add another manual with a genuinely applicable passage. The fixture exposes a query that satisfies relevance and applicability in different objects, producing a convincing parent result without the required source relationship.

Response elementWhat to inspect
Parent hitWhich document was selected
Parent metadataDocument-level applicability
Nested passage hitWhich section produced the match
Passage metadataApplicability of that specific evidence

Return supporting passages explicitly

The official inner_hits reference explains retrieval of matching nested objects. The nested kNN guide shows inner_hits for the passage producing the score. When multiple kNN clauses request inner hits, use distinct names as documented. Request the fields needed to reconstruct evidence, not an assumed arbitrary first paragraph from the parent. Keep passage identifiers and source revision with the returned text.

Validate diversification and citations together

Check whether the intended number of parent documents and supporting passages are returned under the chosen query. Do not interpret parent diversification as proof that every relevant chunk has been enumerated. Resolve the inner hit back to the original section and inspect its conditions. The acceptance artifact is a parent-to-passage evidence chain that respects nested scope, rather than a plausible parent ranking with citations assembled from whichever text was easiest to display.

Related reading: A local RAG server: placing components around the GPU; Vector-database memory: choosing RAM and storage for retrieval.

← All articles