#23173·OpenSearch

RFC: Native Document-Vector Lookup with Graph-Aware Candidate Routing for k-NN

Author: sumantapakiraCreated Sep 29, 2026Updated Oct 1, 2026
LabelsenhancementuntriagedSearch

Is your feature request related to a problem? Please describe

This RFC suggest a new way to execute item-to-item vector search.

It has two parts:

  1. Allow a k-NN query to use the vector stored in an existing document as its query vector, without requiring the application to retrieve and resend that vector.
  2. Optionally you could use a graph-derived routing key stored on that document to narrow the candidate set before the existing k-NN search

The second part is called Graph Residual Quantization (GraphRQ)

Problem statement

OpenSearch supports approximate k-NN search where the caller supplies the query vector.

{ "query": { "knn": { "embedding": { "vector": [0.12, 0.34, 0.56], "k": 20 } } } }

The documented k-NN query therefore expects the query vector itself. And this creates problem for the common operation such as "Find documents similar to X documents".

Lets say document_id = product-123 and the vector is already stored inside OpenSearch. So the application needs to perform 2 operations:-

Application ---- (1)retrieve product-123---> OpenSearch ---return embedding--> Application --- (2)send embedding in k-NN request---> Opensearch ---> k-NN results

This is an overhead which cause round trip.

Secondly, A global vector search may search across a very large corpus: Query vector -> 10,000,000 vectors -> HNSW / ANN search -> top-k

But GraphRQ can provide a graph-derived candidate restriction: Query document -> GraphRQ routing code -> smaller candidate region -> HNSW / ANN search -> top-k

This brings potential benefit of smaller search space and lower search cost.

Describe the solution you'd like

Before describing the proposed solution, lets define what is GraphRQ and what problem it solves.

The basic idea is to use relationships between documents—not only their content vectors—to assign each document a compact discrete routing code.

For example, each document may receive a hierarchical code:

Document A → [17, 4, 12, 8] Document B → [17, 4, 29, 3] Document C → [31, 8, 7, 2]

The individual components can be represented as fields such as:

graphrq_c0 graphrq_c1 graphrq_c2 graphrq_c3

The important property is that documents that are close in the underlying graph can be assigned related routing codes.

Therefore, instead of always searching the entire vector corpus, an application can first use the GraphRQ code to identify a smaller candidate region and then run normal vector similarity search inside that region.

GraphRQ is therefore a routing layer, not a replacement for vector similarity.

Now, how does the solution works:

for #1 use case: The application supplies: Source document ID + vector field ; instead of supplying the actual vector.

Example query:

{ 
"query": { 
    "knn": { 
       "embedding": { 
             "source": { 
                "id": "product-123", 
               "field": "embedding" 
              }, 
             "k": 20 } 
       }
    } 
}

OpenSearch internally performs: product-123 --> Embedding --> query vector --> existing k-NN search No vector needs to be retrieved by the application.

For #2 GraphRQ Extension

The same source document lookup can optionally retrieve a GraphRQ routing field like this:

{ 
"query": { 
    "knn": { 
       "embedding": { 
             "source": { 
                "id": "product-123", 
               "field": "embedding" ,
               "routing_field": "graphrq_c0"
              }, 
             "k": 20 } 
       }
    } 
}

Suppose the source document contains:

{
  "_id": "product-123",
  "embedding": [...],
  "graphrq_c0": 17
}

So the architecture follows this:

Image

Related component

Search

Describe alternatives you've considered

The application retrieves:

  • embedding
  • GraphRQ code

and constructs the query. This works but moves the coordination logic into the application.

Additional context

Provide a native document-backed query-vector source to OpenSearch k-NN that can optionally derive a candidate-routing value from the same source document, allowing applications to perform GraphRQ-aware related-document vector search using only a source document ID while reusing the existing k-NN and filtering infrastructure.

GraphRQ is an offline graph-aware routing scheme that assigns documents compact hierarchical discrete codes, such as [c0,c1,c2,c3], so graph-related regions can be used to narrow the candidate set before final vector-similarity search

Source: opensearch-project/OpenSearch