feat(reranker): add llamacpp reranker provider for llama.cpp /rerank servers#2773
Closed
chethanuk wants to merge 1 commit into
Closed
Conversation
nicoloboschi
requested changes
Jul 20, 2026
nicoloboschi
left a comment
Collaborator
There was a problem hiding this comment.
llamacpp llm provider actually run and manage a llamacpp process so that would not be consistent.
can't you just point use cohere and use custom base url?
|
litellm is also self hosted process and it gets its own variable. |
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.
Summary
Adds first-class
llamacppas a reranker provider (HINDSIGHT_API_RERANKER_PROVIDER=llamacpp), so a localllama-server --rerankinstance can be used directly instead of spoofing theopenrouterprovider with a rewritten base URL. Also documents the existing recipe for llama.cpp embeddings viaHINDSIGHT_API_EMBEDDINGS_PROVIDER=openai+ base URL — the docs-only scope the maintainer confirmed in the issue thread.Fixes #2665
Root cause
llama.cpp already speaks the Jina/Cohere-compatible
/rerankcontract that Hindsight's_CohereCompatibleRerankClientimplements — the only thing missing was a dispatch branch increate_cross_encoder_from_env()plus config constants. No wire-format work was needed.How it works
flowchart LR subgraph env [Config] A["HINDSIGHT_API_RERANKER_PROVIDER=llamacpp<br/>HINDSIGHT_API_RERANKER_LLAMACPP_BASE_URL<br/>(+ optional MODEL / API_KEY / TIMEOUT)"] end A --> B["create_cross_encoder_from_env()"] B -->|"provider == 'llamacpp'"| C["LlamaCppCrossEncoder"] B -->|"missing base URL"| E["ValueError at startup<br/>(same shape as tei)"] C --> D["_CohereCompatibleRerankClient<br/>POST {base_url}/v1/rerank"] D --> F["llama-server --rerank<br/>(reranker GGUF)"] F -->|"results[].index remapped<br/>to input order"| CChanges
LlamaCppCrossEncodercomposing the existing_CohereCompatibleRerankClient(/rerankcontract; permutedresults[].indexremapping covered by a dedicated test)ValueError(same shape astei)ENV_RERANKER_LLAMACPP_*constants, dataclass fields,from_env(), credential fields (base URL + API key)configuration.md+models.mdxreranker sections, plus the llama.cpp embeddings recipe (docs-only, per maintainer scoping).env.example+ bundledhindsight-embedtemplate kept in sync (test_bundled_template_matches_repo_rootguards this)openrouter(dispatched but missing from the message);skills/hindsight-docsregenerated in-sync with the docs change; score-normalization docstring corrected to match the conditional-sigmoid behavior inreranking.pyHow to test
Test evidence
Run post-rebase on upstream
main(ca87e2989), squashed branch:test_llamacpp_cross_encoder.py+test_reranker_timeouts.py+test_cohere_cross_encoder.pyhindsight-embed/tests/test_env_template.py(template sync)ruff check/ruff format --checkon touched filesty check hindsight_api/engine/cross_encoder.pyNotes for reviewers
llama-server --rerank; it does not spawn one (unlike thellamacppLLM provider).RERANK_BASE_URLfor arbitrary Jina/Cohere-spec servers (raised by @adoreparler in the issue thread), ollama reranker, per-bank reranker config.