Skip to content

feat(embed): add LiteLLM text prompt prefixes - #311

Open
faysou wants to merge 1 commit into
cocoindex-io:mainfrom
faysou:feature/litellm-prompt-prefix
Open

faysou wants to merge 1 commit into
cocoindex-io:mainfrom
faysou:feature/litellm-prompt-prefix

Conversation

@faysou

@faysou faysou commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Summary

LiteLLM indexing_params and query_params now accept prompt, a literal prefix prepended to each text before the embedding request. This lets models that expect task prefixes, such as EmbeddingGemma (title: none | text: for documents, task: code retrieval | query: for queries), run behind OpenAI-compatible servers like llama.cpp, which apply no model prompts of their own.

embedding:
  provider: litellm
  model: openai/embeddinggemma-2
  indexing_params:
    prompt: 'title: none | text: '
  query_params:
    prompt: 'task: code retrieval | query: '
envs:
  OPENAI_BASE_URL: http://127.0.0.1:8080/v1

Design

prompt is applied in PacedLiteLLMEmbedder.run_embedding_request and never forwarded to litellm.aembedding. create_embedder passes indexing_params to the constructor as default kwargs, so handling it at the request boundary covers both paths: a per-call prompt (query side) overrides the constructor default (indexing side), and neither reaches the server as an unknown API parameter.

prompt joins input_type in the accepted LiteLLM keys, the ccc init template comment, and the README.

Validation

  • uv run pytest tests/test_litellm_embedder.py tests/test_embedder_params.py tests/test_embed_params_forwarding.py tests/test_settings.py: 98 passed.
  • uv run ruff check src tests and uv run mypy src pass.
  • Indexed a large multi-repository workspace through llama.cpp serving EmbeddingGemma 2 with these prompts; ccc doctor passes both model checks.

- Accept `prompt` in LiteLLM `indexing_params` and `query_params`
- Prepend it to each text before the request instead of sending it as an API parameter
- Support OpenAI-compatible servers such as llama.cpp that apply no model prompts

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant