Solr 9 Dense Vectors and the knn Query Parser

Account Resources

Solr 9.0 is the release that let Solr match documents by meaning, not only by the words they contain. Two additions do it: a field type that stores vectors and a query parser that finds the nearest ones.

Solr 9.0 introduced the DenseVectorField field type and the {!knn} query parser. Before that release Solr could only match documents by the words they contained. After it, Solr can also match documents by meaning, by comparing an embedding of the query against embeddings stored in the index.

This is not a footnote on the Solr 9 feature list. It is the single reason every AI capability on Opensolr exists: Hybrid Search, AI Hints, the AI Document Reader, retrieval-augmented answers, and search by image all read from a dense vector field. None of them can run on a Solr 8 index, because there is no field type there to hold the vectors.

ONE QUERY, TWO RANKINGS, ONE RESULT LISTVisitor queryone HTTP requestBM25 lexical scoringwords the document contains{!knn} vector scoringmeaning, via DenseVectorFieldOne ranked listOpensolr hybrid parser

The Opensolr {!hybrid} parser scores a query twice and fuses the two rankings. The right-hand half of that fusion is pure Solr 9.

DenseVectorField

A field type that stores a fixed-length float vector per document, indexed with the HNSW graph structure from Lucene 9. You declare the dimension and the similarity function once, in the schema.

The {!knn} query parser

Takes a query vector and returns the topK nearest documents by cosine, dot product or Euclidean distance. It composes with filter queries, so vector recall and business rules coexist.

What it powers on Opensolr

Hybrid Search, AI Hints, the AI Document Reader, RAG answers and search by image. All of them are dense vector lookups underneath a friendlier name.

What Solr 8 and older cannot do

Nothing about vectors was backported. On Solr 7 or 8 there is no vector field, no {!knn}, and therefore no semantic recall of any kind. This is the concrete reason to move.

This is the definition in the configuration that Opensolr indexes in the regions with site search are created with:

<fieldType name="knn_vector" class="solr.DenseVectorField"
           vectorDimension="1024" similarityFunction="cosine"/>

<field name="embeddings" type="knn_vector" indexed="true" stored="false"/>
On Opensolr you do not build that schema by hand: indexes in the regions with site search come with it, and with the embedding pipeline and the hybrid parser (regions). Full detail in hybrid search.

Solr 9

Dense vectors and the knn query parser (this page)