Chroma: collections use the L2 space but scores assume cosine distance, so scores and score thresholds are wrong
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #47084 by @laoyyu — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 60/100
Research direction
Start from ChromaVector.create_collection, add_texts and search_by_vector in the Chroma vector-store adapter: create_collection passes no distance space, and search_by_vector scores as 1 - distance. Reproduce with the snippet against ghcr.io/chroma-core/chroma:0.5.20 using unit-length embeddings, then make the score follow the collection's space so existing l2 collections report 1 - distance/2. Done when threshold 0.0 returns all five chunks, 0.7 returns only the 0.95 and 0.8 ones, and hit testing reports the same scores.
Written by the indexing model from the issue text.
Description
Self Checks
- I have read the Contributing Guide and Language Policy.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
Dify version
main (580416d, api 1.20.0)
Cloud or Self Hosted
Self Hosted (Source)### Steps to reproduce
Against ghcr.io/chroma-core/chroma:0.5.20 (the image in docker-compose), with unit-length embeddings whose cosine similarity to the query is 0.95, 0.8, 0.6, 0.45 and 0.2:
vector.create(texts=docs, embeddings=embeddings)
vector.search_by_vector(query, top_k=5, score_threshold=0.0)
vector.search_by_vector(query, top_k=5, score_threshold=0.7)
✔️ Expected Behavior
metadata["score"] is the cosine similarity, as with pgvector, Weaviate and the other backends: threshold 0.0 returns all 5 chunks (scores 0.95 ... 0.2) and threshold 0.7 returns the 0.95 and 0.8 chunks.
❌ Actual Behavior
The scores are 0.9, 0.6 and 0.2 (that is, 2 x cosine - 1), threshold 0.0 returns only 3 chunks (the 0.45 and 0.2 ones are dropped), and threshold 0.7 returns only the 0.95 chunk.
ChromaVector.create_collection and add_texts call get_or_create_collection(name) without a distance space, so Chroma uses its default l2 (squared Euclidean) space, but search_by_vector computes the score as 1 - distance, which is only right for cosine distance. For unit vectors the squared L2 distance is 2 - 2 x cosine, so every score is too low, chunks with a cosine below 0.5 are never returned, and a score threshold is stricter than configured. Hit testing shows the same wrong scores.
A possible fix: create new collections with metadata={"hnsw:space": "cosine"}, and compute the score from the collection's space so existing l2 collections also report the cosine similarity (1 - distance / 2 for unit vectors). Happy to send a PR if that approach is fine.
- Dominant language
- Python
- Stars
- 162k
- Forks
- 25.6k
- Avg merge
- 15h 9m
- Merged PRs (30d)
- 606
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from langgenius/dify
-
OpenSearch: text_exists() queries OpenSearch _id instead of metadata.doc_id, so it always returns False for indexed chunksPossibly taken @SanemIzci claimed this 1 day ago. Open🐞 bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
langgenius/dify#47109 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Log only execution identifiers when a workflow worker starts a runPossibly taken @kinglegendzzh claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langgenius/dify#47094 · 2 reactions ·
Maintainers usually reply within 1 day
-
Node.js SDK declares a response body for 204 conversation deletionPossibly taken @Wang-Zephyr claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
langgenius/dify#46883 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Provider IDs with a trailing newline are silently accepted and propagatedPossibly taken @Batianxieshen1 claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/dify#46875 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Agent Python SDK polling rejects function-tool results that SSE acceptsPossibly taken @EndlessRoad-max claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
langgenius/dify#46868 · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/graphon#443 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
[BUG]: Management endpoints /v1/memory/stats and /v1/memory/counts bypass API key authenticationOpen
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
docling-project/docling-serve#788 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
opensearch-project/cross-cluster-replication#1805 ·
Maintainers usually reply within 1 day