Follow-up to #1264 and PR #1265 (credit to @Aryan-Pardeshi for the initial attempt and to the #1264 reporter for the cosine-margin measurements showing the retrieval impact).
Problem
FastEmbed queries are embedded through the passage path, so asymmetric model families (E5: query: / passage: prefixes) lose their role prefixes and retrieval quality degrades (#1264).
PR #1265 rerouted embed_query to FastEmbed's query_embed, but in fastembed 0.8.0 query_embed is a passthrough to embed for both the default BAAI/bge-small-en-v1.5 (OnnxTextEmbedding) and the E5 family (PooledEmbedding) — only JinaEmbeddingV3 overrides it. The change therefore produces byte-identical vectors for the reported case.
Proposed fix
- Wire per-model-family default prefixes (E5:
query: / passage: ) through the existing PrefixingEmbeddingProvider path (src/basic_memory/repository/prefixing_provider.py). Prefixes are already hashed into provider identity (prefixing_embedding_identity, wired in embedding_provider_factory.py), so changed document semantics automatically trigger reindex.
- Keep a
query_embed call for models that genuinely implement it (Jina v3), layered under the prefixing wrapper.
- Regression test shaped like the real dispatch: underlying
query_embed delegates to embed, and recorded inputs still receive both role prefixes.
Workaround available today
semantic_embedding_query_prefix / semantic_embedding_document_prefix config already applies prefixes for any provider, including FastEmbed E5 models.
Notes
- Applying document prefixes changes stored vectors, so the fix must ride the provider-identity reindex path (it does, by construction, via item 1).
bge-* models also document a recommended query instruction ('Represent this sentence for searching relevant passages: ') — worth deciding whether the default map covers BGE too or E5 only in the first pass.
Follow-up to #1264 and PR #1265 (credit to @Aryan-Pardeshi for the initial attempt and to the #1264 reporter for the cosine-margin measurements showing the retrieval impact).
Problem
FastEmbed queries are embedded through the passage path, so asymmetric model families (E5:
query:/passage:prefixes) lose their role prefixes and retrieval quality degrades (#1264).PR #1265 rerouted
embed_queryto FastEmbed'squery_embed, but in fastembed 0.8.0query_embedis a passthrough toembedfor both the defaultBAAI/bge-small-en-v1.5(OnnxTextEmbedding) and the E5 family (PooledEmbedding) — onlyJinaEmbeddingV3overrides it. The change therefore produces byte-identical vectors for the reported case.Proposed fix
query:/passage:) through the existingPrefixingEmbeddingProviderpath (src/basic_memory/repository/prefixing_provider.py). Prefixes are already hashed into provider identity (prefixing_embedding_identity, wired inembedding_provider_factory.py), so changed document semantics automatically trigger reindex.query_embedcall for models that genuinely implement it (Jina v3), layered under the prefixing wrapper.query_embeddelegates toembed, and recorded inputs still receive both role prefixes.Workaround available today
semantic_embedding_query_prefix/semantic_embedding_document_prefixconfig already applies prefixes for any provider, including FastEmbed E5 models.Notes
bge-*models also document a recommended query instruction ('Represent this sentence for searching relevant passages: ') — worth deciding whether the default map covers BGE too or E5 only in the first pass.