Skip to content

Apply E5 query/passage prefixes via the prefixing provider defaults (FastEmbed asymmetry) #1284

Description

@phernandez

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

  1. 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.
  2. Keep a query_embed call for models that genuinely implement it (Jina v3), layered under the prefixing wrapper.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions