feat: Add task-aware embedding support#2560
Open
StoreksFeed wants to merge 6 commits intoHKUDS:mainfrom
Open
Conversation
Collaborator
|
Thank you for your valuable contribution. Please resolve the existing conflicts so we can proceed with the review and merger. |
Collaborator
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93d5ce0283
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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.
Description
Modern embedding models (e.g., Gemini and FRIDA) support asymmetric embeddings through task-specific prefixes, which significantly improve retrieval accuracy by generating different embeddings for queries versus documents. This PR implements this capability in LightRAG.
Related Issues
N/A
Changes Made
Configuration & Documentation
EMBEDDING_DOCUMENT_PREFIXandEMBEDDING_QUERY_PREFIXenvironment variables tolightrag/api/config.pydocs/DockerDeployment.mdandenv.examplewith new configuration optionsexamples/unofficial-sample/lightrag_embedding_prefixes.pyCore Infrastructure
EmbeddingFuncwrapper inlightrag/utils.pywithsupports_contextparameterwrap_embedding_func_with_attrsdecorator to support context-aware functionslightrag/operate.pyto passcontextVector Storage Backends
Updated all storage implementations to use context parameter:
lightrag/kg/faiss_impl.pylightrag/kg/milvus_impl.pylightrag/kg/mongo_impl.pylightrag/kg/nano_vector_db_impl.pylightrag/kg/postgres_impl.pylightrag/kg/qdrant_impl.pyLLM Provider Bindings
Updated embedding functions with context support:
lightrag/llm/openai.py- Prefix supportlightrag/llm/ollama.py- Prefix supportlightrag/llm/gemini.py- Automatic task_type selectionlightrag/llm/jina.py- Automatic task selectionlightrag/llm/hf.py- Prefix supportBinding Options
GeminiEmbeddingOptionsto support automatic task_type selectionAPI Server
lightrag/api/lightrag_server.pylightrag/api/utils_api.pysplash screen to display prefix settingsChecklist
Additional Notes
Backward Compatibility
EMBEDDING_DOCUMENT_PREFIXorEMBEDDING_QUERY_PREFIXenvironment variables are set