Repository navigation
docs(sdk): note that custom embeddings must be unit-normalized - #529
VeshRaazThapa wants to merge 1 commit into
Conversation
Moss does not normalize caller-provided vectors, so rankings only match cosine similarity when document and query embeddings are unit length. The existing examples use OpenAI, which returns normalized vectors, so the requirement is invisible there; local models often return un-normalized vectors and rank differently. Adds a short note to the custom-embeddings section of the Python and JavaScript SDK READMEs.
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe JavaScript and Python SDK READMEs now document that Moss does not normalize caller-provided embeddings. They explain when cosine-similarity ranking matches and how unnormalized vectors can change result ordering. ChangesEmbedding documentation
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~3 minutes Change: Other 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
Codex reviewNo issues found. |
Summary
The custom-embeddings sections of the Python and JavaScript SDK READMEs do not say that Moss does not normalize caller-provided vectors. Rankings only match cosine similarity when document and query embeddings are unit length.
The existing examples use OpenAI, which returns normalized vectors, so the requirement is invisible there. Local models often return un-normalized vectors and rank differently.
How I found it
Plugging a local static embedding model (a model2vec distillation of LaBSE, 256-d) into
DocumentInfo(embedding=...)andQueryOptions(embedding=...)onmoss1.13.0. On a 20-query Nepali-to-English test set, raw vectors gave 14/20 top-1 inside Moss while local cosine gave 17/20. L2-normalizing the vectors before sending them made Moss return 17/20, identical to local cosine.Demo and numbers: https://github.com/VeshRaazThapa/moss-nepali-demo
Changes
sdks/python/sdk/README.md: short note after the custom-embeddings examplesdks/javascript/sdk/README.md: same noteDocs only, no code changes.
Summary by CodeRabbit