Skip to content

feat: Add task-aware embedding support#2560

Open
StoreksFeed wants to merge 6 commits intoHKUDS:mainfrom
StoreksFeed:embedding-prefixes
Open

feat: Add task-aware embedding support#2560
StoreksFeed wants to merge 6 commits intoHKUDS:mainfrom
StoreksFeed:embedding-prefixes

Conversation

@StoreksFeed
Copy link
Contributor

@StoreksFeed StoreksFeed commented Dec 30, 2025

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

  • Added EMBEDDING_DOCUMENT_PREFIX and EMBEDDING_QUERY_PREFIX environment variables to lightrag/api/config.py
  • Updated docs/DockerDeployment.md and env.example with new configuration options
  • Added example demonstrating prefix usage: examples/unofficial-sample/lightrag_embedding_prefixes.py

Core Infrastructure

  • Enhanced EmbeddingFunc wrapper in lightrag/utils.py with supports_context parameter
  • Updated wrap_embedding_func_with_attrs decorator to support context-aware functions
  • Modified lightrag/operate.py to pass context

Vector Storage Backends

Updated all storage implementations to use context parameter:

  • lightrag/kg/faiss_impl.py
  • lightrag/kg/milvus_impl.py
  • lightrag/kg/mongo_impl.py
  • lightrag/kg/nano_vector_db_impl.py
  • lightrag/kg/postgres_impl.py
  • lightrag/kg/qdrant_impl.py

LLM Provider Bindings

Updated embedding functions with context support:

  • lightrag/llm/openai.py - Prefix support
  • lightrag/llm/ollama.py - Prefix support
  • lightrag/llm/gemini.py - Automatic task_type selection
  • lightrag/llm/jina.py - Automatic task selection
  • lightrag/llm/hf.py - Prefix support

Binding Options

  • Updated GeminiEmbeddingOptions to support automatic task_type selection

API Server

  • Integrated prefix configuration into lightrag/api/lightrag_server.py
  • Updated lightrag/api/utils_api.py splash screen to display prefix settings

Checklist

  • Changes tested locally
  • Code reviewed
  • Documentation updated (if necessary)
  • Unit tests added (if applicable)

Additional Notes

Backward Compatibility

  • Fully backward compatible - task is not injected unless explicitly asked
  • Existing deployments without prefix configuration should continue to work unchanged
  • Optional feature activated only when EMBEDDING_DOCUMENT_PREFIX or EMBEDDING_QUERY_PREFIX environment variables are set

@StoreksFeed StoreksFeed changed the title feat: Add context-aware embedding support with prefixes feat: Add task-aware embedding support Jan 16, 2026
@danielaskdd danielaskdd added enhancement New feature or request tracked Issue is tracked by project labels Mar 2, 2026
@danielaskdd
Copy link
Collaborator

Thank you for your valuable contribution. Please resolve the existing conflicts so we can proceed with the review and merger.

@danielaskdd
Copy link
Collaborator

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tracked Issue is tracked by project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants