fix: separate document and query prefixes for embedding models#11985
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: separate document and query prefixes for embedding models#11985roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
Adds EmbeddingPurpose type and documentPrefix field to support different prefixes for indexing vs querying. Models like nomic-embed-code require a query prefix for search but no prefix for document indexing. - Add documentPrefix to EmbeddingModelProfile type - Add getModelDocumentPrefix() and getModelPrefixForPurpose() helpers - Add purpose parameter to IEmbedder.createEmbeddings() - Update all embedder implementations to use purpose-aware prefixing - Scanner and file-watcher pass "index" purpose - Search service passes "query" purpose - Update nomic-embed-code profiles (no documentPrefix for indexing) - Update tests for new behavior Closes #11707
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11707
Description
This PR attempts to address Issue #11707 by separating document (indexing) and query (search) prefixes for embedding models. Feedback and guidance are welcome.
Problem: The
queryPrefixinEmbeddingModelProfilewas applied to all texts indiscriminately -- both during indexing (scanner/file-watcher) and during search queries. Most modern embedding models (including nomic-embed-code) require different instructions for indexing vs querying, or at minimum: no prefix for indexing and a specific prefix for querying.Solution:
EmbeddingPurposetype ("index" | "query") to@roo-code/typesdocumentPrefixfield toEmbeddingModelProfilefor indexing/document embeddinggetModelDocumentPrefix()andgetModelPrefixForPurpose()helperspurposeparameter toIEmbedder.createEmbeddings():"index"-> usesdocumentPrefix(for document indexing)"query"orundefined-> usesqueryPrefix(backward compatible)"index"purpose"query"purposequeryPrefixkept for search,documentPrefixintentionally omitted (undefined) since nomic does not require a prefix for document indexingBackward compatibility: Models without
documentPrefixcontinue to work exactly as before. Thepurposeparameter is optional and defaults toqueryPrefixbehavior when omitted.Test Procedure
embeddingModels.spec.tscoveringgetModelQueryPrefix,getModelDocumentPrefix, andgetModelPrefixForPurposepurposeparameter passthroughPre-Submission Checklist
Documentation Updates
Additional Notes
This change is fully backward compatible. Existing callers that do not pass a
purposewill continue to usequeryPrefixas before.Interactively review PR in Roo Code Cloud