Skip to content

Catalog dense vector - #549

Draft
christinach wants to merge 6 commits into
mainfrom
catalog-denseVector
Draft

Catalog dense vector#549
christinach wants to merge 6 commits into
mainfrom
catalog-denseVector

Conversation

@christinach

@christinach christinach commented May 28, 2026

Copy link
Copy Markdown
Member

related to pulibrary/dacs_handbook#351

Adds a new handler to use it in the catalog semantic search. It works with defType lucene.

The dense vector field uses the knn algorithm https://solr.apache.org/guide/solr/latest/query-guide/dense-vector-search.html#densevectorfield

https://solr.apache.org/guide/solr/latest/upgrade-notes/major-changes-in-solr-9.html#solr-9-0

The text embeddings were generated locally using pulibrary/dedup-text-embeddings#1 and the model 'multi-qa-mpnet-base-cos-v1'

To search using the knn index , solr expects a q param of "{!knn f=text_embeddings topK=10}[0.010338805615901947,0.02806314453482628,0.020983939990401268]" and with solr9 we need to set the defType to lucene.

http://localhost:61903/solr/orangelight-core-dev/select?defType=lucene&indent=true&q.op=OR&q=%7B!knn%20f%3Dtext_embeddings%20topK%3D10%7D%5B0.010338805615901947%2C0.02806314453482628%2C0.020983939990401268%5D&useParams=

{
  "responseHeader":{
    "status":0,
    "QTime":8,
    "params":{
      "q":"{!knn f=text_embeddings topK=10}[0.010338805615901947,0.02806314453482628,0.020983939990401268]",
      "defType":"lucene",
      "indent":"true",
      "q.op":"OR",
      "useParams":""
    }
  },
  "response":{
    "numFound":2,
    "start":0,
    "maxScore":0.9992631,
    "numFoundExact":true,
    "docs":[{
      "id":"9923849243506421",
      "title_display":"Vercingétorix. Histoire du pays gaulois depuis ses origines jusqu'à la conquête romaine",
      "author_display":["Colomb, Georges"],
      "score":0.9992631
    },{
      "id":"9923843813506421",
      "title_display":"The bright land",
      "author_display":["Fairbank, Janet Ayer"],
      "score":0.7314496
    }]
  },
  "facet_counts":{
    "facet_queries":{ },
    "facet_fields":{
      "format":[ ],
      "language_facet":[ ],
      "pub_date_start_sort":[ ],
      "advanced_location_s":[ ]
    },
    "facet_ranges":{ },
    "facet_intervals":{ },
    "facet_heatmaps":{ }
  }
}

will be overridden by parameters in the request
-->
<lst name="defaults">
<str name="defType">lucene</str>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs defType lucene to work

users normally should not need to know about them.
-->
<fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
<fieldType name="knn_vector" class="solr.DenseVectorField" vectorDimension="3" similarityFunction="cosine" knnAlgorithm="hnsw" hnswMaxConnections="10" hnswBeamWidth="40" />

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vectorDimension= 3 is just for testing the knn query and the /semantic handler locally. It is not a realistic vector dimension.
The specific model by default creates vectors with dimensions 768.
In order to reduce the size of the vectors we would need to use a method like PCA which is also used in https://github.com/pulibrary/dedup-text-embeddings/blob/main/ipca_on_embeddings.py for a different purpose. Or train the model with a smaller size of vectors.

we encode the text_embeddings to binary
with values between 127 and -127
This produces a vector with dimension 96.

update the solr schema.xml to use vectorDimension="96"
and similarityFunction="dot_product"
we generate float32 embeddings through the emebedding service
use 384 dimensions which is the defualt diemsnion number for model all-MiniLM-L6-v2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant