Skip to content

Support caller-supplied query embeddings in ChromaVectorStore - #7144

Open
lejuho wants to merge 1 commit into
spring-projects:mainfrom
lejuho:chroma-query-embedding-search
Open

lejuho wants to merge 1 commit into
spring-projects:mainfrom
lejuho:chroma-query-embedding-search

Conversation

@lejuho

@lejuho lejuho commented Oct 13, 2026

Copy link
Copy Markdown

Summary

VectorStoreRetriever.similaritySearch(float[], SearchRequest) lets callers search with a precomputed query embedding (added in 89dc8db for pgvector, Redis, Elasticsearch, and Qdrant). ChromaVectorStore already queried by float[] through its collection path, but did not override doSimilaritySearch(float[], SearchRequest), so the new API threw UnsupportedOperationException.

Wire Chroma the same way as Elasticsearch: validate the query vector width against the embedding model's reported dimensions and reuse the existing collection query path. Also copy Chroma metadata into a mutable map before adding the distance field, so an immutable metadata map from the API cannot fail the search. Update the vector-store docs to list Chroma among the stores that support caller-supplied query embeddings.

Tests

  • shouldSearchWithCallerSuppliedQueryEmbeddingWithoutEmbeddingModel — searches with a float[] and never calls EmbeddingModel.embed
  • shouldRejectWrongWidthQueryEmbedding — rejects a dimension mismatch
  • ./mvnw -Dmaven.build.cache.enabled=false -pl vector-stores/spring-ai-chroma-store test -Dtest='ChromaVectorStoreTests,ChromaApiTest,ChromaFilterExpressionConverterWhereJsonTests' -Ddisable.checks=false — 10 tests, 0 failures

Prior art: Elasticsearch / pgvector / Redis / Qdrant in 89dc8db; OpenSearch in #7140.

Wire Chroma into VectorStoreRetriever.similaritySearch(float[], SearchRequest)
the same way as Elasticsearch/pgvector/Redis/Qdrant (and OpenSearch spring-projects#7140):
validate the query vector width against the embedding model dimensions and
reuse the existing collection query path. Copy Chroma metadata before adding
the distance field so immutable maps from the API cannot fail the search.

Signed-off-by: lejuho <zedd1324@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants