feat: add semantic embedding text prefixes#1044
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f7198d58a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Signed-off-by: Dmitry Golubev <lastguru@gmail.com>
7f7198d to
0818b8d
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Summary
Adds optional role-specific literal text prefixes for semantic embeddings:
semantic_embedding_document_prefixsemantic_embedding_query_prefixThese prefixes are prepended to the actual text sent to the embedding provider:
Fixes #1008.
Why
Some embedding models require role-specific text prefixes as part of the input string, not as API parameters.
Examples include models where the recommended input format is something like:
title: none | text: ...task: search result | query: ...Basic Memory already supports LiteLLM
input_typesettings, but that only helps providers that understand an API-level role parameter. OpenAI-compatible endpoints such as TEI just receive theinputstrings, so prefix-sensitive models cannot currently be used in their recommended form without a proxy or local patch.Without this, retrieval quality evaluation is misleading: a model can look worse than it really is because documents and queries are embedded without the format it was trained/evaluated with.
Implementation
fastembed,openai, andlitellm.input_typeand literal text prefixes.Validation
201 passedfocused teststy check src tests test-intgit diff --check