AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): default Graphiti reranker to gpt-4.1-mini (#15150)
Nicholas Tindled953c7fd0f90
diff --git a/autogpt_platform/backend/backend/copilot/graphiti/client.py b/autogpt_platform/backend/backend/copilot/graphiti/client.pyindex af0d1856c7..c1217732b5 100644--- a/autogpt_platform/backend/backend/copilot/graphiti/client.py+++ b/autogpt_platform/backend/backend/copilot/graphiti/client.py@@ -222,9 +222,9 @@ def _build_graphiti(# P-1.4: cross-encoder reranker for warm-context retrieval.# Runs concurrent boolean-classifier prompts (one per candidate- # edge) and uses log-probabilities to rank. Cheap because the- # reranker model defaults to gpt-4.1-nano — the cost is one batch- # of small calls per session-start search. The Compat subclass+ # edge) and uses log-probabilities to rank. Costs one small call per+ # candidate (up to 2 * context_max_facts) on the reranker model+ # (gpt-4.1-mini by default) per session-start search. The Compat subclass# fixes the stock client's max_tokens=1, which OpenAI-compatible# upstreams now reject with a 400 (minimum is 16).if cross_encoder is None:diff --git a/autogpt_platform/backend/backend/copilot/graphiti/config.py b/autogpt_platform/backend/backend/copilot/graphiti/config.pyindex 9b104d3851..791cf2a309 100644--- a/autogpt_platform/backend/backend/copilot/graphiti/config.py+++ b/autogpt_platform/backend/backend/copilot/graphiti/config.py@@ -21,7 +21,7 @@ _BACKEND_ROOT = Path(__file__).resolve().parents[3]# the validator can't drift — same pattern as# ``copilot/config.py::_DEFAULT_TITLE_MODEL`` etc._DEFAULT_LLM_MODEL = "gpt-4.1-mini"-_DEFAULT_RERANKER_MODEL = "gpt-4.1-nano"+_DEFAULT_RERANKER_MODEL = "gpt-4.1-mini"_DEFAULT_EMBEDDER_MODEL = "text-embedding-3-small"# Local-transport defaults. Mirrors dev's chat-side ``--with-ollama``@@ -91,11 +91,11 @@ class GraphitiConfig(BaseSettings):# Cross-encoder reranker (P-1.4) — used by warm-context retrieval to# rerank top edges from BM25 + cosine + BFS. Graphiti's built-in# OpenAIRerankerClient runs concurrent boolean-classifier prompts- # against gpt-4.1-nano by default (one prompt per candidate; log-- # probabilities decide the score). The audit estimated ~10–15%- # precision lift on warm context at the cost of one LLM call per- # session start. Defaults match Graphiti's own default so the- # reranker can ship with no env config.+ # (one prompt per candidate; log-probabilities decide the score).+ # This config defaults the classifier to gpt-4.1-mini — the same+ # cloud slug as ``llm_model`` — so the reranker can ship with no+ # env config, at the cost of up to 2 * context_max_facts classifier+ # calls per session start.reranker_model: str = Field(default=_DEFAULT_RERANKER_MODEL,description="Model for the cross-encoder reranker. Cheap, fast classifier prompts.",@@ -278,7 +278,7 @@ class GraphitiConfig(BaseSettings):- ``llm_model`` (``gpt-4.1-mini``) → ``hf.co/ornith-ai/Ornith-1.5-9B-GGUF:Q4_K_M``(matches dev's chat default — one Ollama pull powers bothsurfaces; vetted for structured output / tool-calling shape).- - ``reranker_model`` (``gpt-4.1-nano``) → same Ornith slug.+ - ``reranker_model`` (``gpt-4.1-mini``) → same Ornith slug.Reranker prompts are simpler than extraction; reusing thechat model avoids pulling a second model just for reranking.- ``embedder_model`` (``text-embedding-3-small``) →diff --git a/autogpt_platform/backend/backend/copilot/graphiti/config_test.py b/autogpt_platform/backend/backend/copilot/graphiti/config_test.pyindex f2b1b827e0..355d78e836 100644--- a/autogpt_platform/backend/backend/copilot/graphiti/config_test.py+++ b/autogpt_platform/backend/backend/copilot/graphiti/config_test.py@@ -18,6 +18,9 @@ _ENV_VARS_TO_CLEAR = ("CHAT_USE_OPENROUTER","CHAT_USE_CLAUDE_CODE_SUBSCRIPTION","CHAT_BASE_URL",+ "GRAPHITI_LLM_MODEL",+ "GRAPHITI_RERANKER_MODEL",+ "GRAPHITI_EMBEDDER_MODEL",)@@ -188,10 +191,13 @@ class TestApplyLocalGraphitiModels:``GRAPHITI_*_MODEL`` env var per slot. Mirrors dev's``_apply_local_aux_models`` pattern on the chat side."""+ @pytest.mark.parametrize("reranker_override", [None, "gpt-4.1-mini"])def test_rewrites_cloud_defaults_under_local(- self, monkeypatch: pytest.MonkeyPatch+ self, monkeypatch: pytest.MonkeyPatch, reranker_override: str | None) -> None:_patch_chat_cfg(monkeypatch, _local_chat_cfg())+ if reranker_override is not None:+ monkeypatch.setenv("GRAPHITI_RERANKER_MODEL", reranker_override)cfg = GraphitiConfig()# llm_model: gpt-4.1-mini → Ornith-1.5-9B GGUFassert cfg.llm_model == "hf.co/ornith-ai/Ornith-1.5-9B-GGUF:Q4_K_M"@@ -209,9 +215,11 @@ class TestApplyLocalGraphitiModels:rewrites *literal* cloud defaults."""_patch_chat_cfg(monkeypatch, _local_chat_cfg())monkeypatch.setenv("GRAPHITI_LLM_MODEL", "qwen3:8b")+ monkeypatch.setenv("GRAPHITI_RERANKER_MODEL", "custom-reranker:tag")monkeypatch.setenv("GRAPHITI_EMBEDDER_MODEL", "all-minilm")cfg = GraphitiConfig()assert cfg.llm_model == "qwen3:8b"+ assert cfg.reranker_model == "custom-reranker:tag"assert cfg.embedder_model == "all-minilm"def test_cloud_defaults_preserved_under_cloud_transport(@@ -230,9 +238,24 @@ class TestApplyLocalGraphitiModels:)cfg = GraphitiConfig()assert cfg.llm_model == "gpt-4.1-mini"- assert cfg.reranker_model == "gpt-4.1-nano"+ assert cfg.reranker_model == "gpt-4.1-mini"assert cfg.embedder_model == "text-embedding-3-small"+ def test_reranker_env_override_under_cloud_transport(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ _patch_chat_cfg(+ monkeypatch,+ ChatConfig(+ use_openrouter=True,+ api_key="or-key",+ base_url="https://openrouter.ai/api/v1",+ ),+ )+ monkeypatch.setenv("GRAPHITI_RERANKER_MODEL", "gpt-5.6-luna")+ cfg = GraphitiConfig()+ assert cfg.reranker_model == "gpt-5.6-luna"+class TestIsEnabledForUser:@pytest.mark.asynciodiff --git a/autogpt_platform/backend/backend/copilot/graphiti/reranker.py b/autogpt_platform/backend/backend/copilot/graphiti/reranker.pyindex cb17ab5ceb..4bef93cf4b 100644--- a/autogpt_platform/backend/backend/copilot/graphiti/reranker.py+++ b/autogpt_platform/backend/backend/copilot/graphiti/reranker.py@@ -40,7 +40,7 @@ logger = logging.getLogger(__name__)# logit_bias restricts the vocabulary to "True"/"False").MIN_COMPLETION_TOKENS = 16-DEFAULT_MODEL = "gpt-4.1-nano"+DEFAULT_MODEL = "gpt-4.1-mini"class CompatOpenAIRerankerClient(OpenAIRerankerClient):diff --git a/autogpt_platform/backend/backend/copilot/graphiti/reranker_test.py b/autogpt_platform/backend/backend/copilot/graphiti/reranker_test.pyindex b87eaf305f..0b2cfb0705 100644--- a/autogpt_platform/backend/backend/copilot/graphiti/reranker_test.py+++ b/autogpt_platform/backend/backend/copilot/graphiti/reranker_test.py@@ -15,6 +15,8 @@ from unittest.mock import AsyncMock, MagicMockimport pytestfrom graphiti_core.llm_client import LLMConfig+from backend.copilot.graphiti import client as client_mod+from backend.copilot.graphiti.config import GraphitiConfigfrom backend.copilot.graphiti.reranker import CompatOpenAIRerankerClient@@ -55,7 +57,7 @@ async def test_rank_requests_at_least_sixteen_max_tokens():[_logprob_response("True", -0.1), _logprob_response("False", -0.2)])reranker = CompatOpenAIRerankerClient(- config=LLMConfig(api_key="k", model="gpt-4.1-nano"), client=client+ config=LLMConfig(api_key="k", model="gpt-4.1-mini"), client=client)await reranker.rank("query", ["passage a", "passage b"])@@ -77,7 +79,7 @@ async def test_rank_scores_true_above_false_and_sorts():[_logprob_response("False", -0.05), _logprob_response("True", -0.05)])reranker = CompatOpenAIRerankerClient(- config=LLMConfig(api_key="k", model="gpt-4.1-nano"), client=client+ config=LLMConfig(api_key="k", model="gpt-4.1-mini"), client=client)ranked = await reranker.rank("query", ["irrelevant", "relevant"])@@ -96,7 +98,7 @@ async def test_rank_handles_empty_logprobs_without_desync():[_logprob_response("True", -0.05), _empty_logprob_response()])reranker = CompatOpenAIRerankerClient(- config=LLMConfig(api_key="k", model="gpt-4.1-nano"), client=client+ config=LLMConfig(api_key="k", model="gpt-4.1-mini"), client=client)ranked = await reranker.rank("query", ["relevant", "no_response"])@@ -105,11 +107,30 @@ async def test_rank_handles_empty_logprobs_without_desync():assert dict(ranked)["no_response"] == 0.0-def test_build_graphiti_uses_compat_reranker(mocker):+ "model, expected_model",+ [+ (None, "gpt-4.1-mini"),+ ("", "gpt-4.1-mini"),+ ("custom-reranker", "custom-reranker"),+ ],+)+async def test_rank_uses_configured_model_or_default(model, expected_model):+ client, captured = _client_with([_logprob_response("True", -0.1)])+ reranker = CompatOpenAIRerankerClient(+ config=LLMConfig(api_key="k", model=model), client=client+ )++ await reranker.rank("query", ["passage"])++ assert captured[0]["model"] == expected_model+++async def test_build_graphiti_uses_compat_reranker(mocker):"""client.py must construct the patched reranker, not the stockone — otherwise the 400s come back on the next refactor."""- from backend.copilot.graphiti import client as client_mod-captured: dict = {}class _FakeGraphiti:@@ -117,11 +138,26 @@ def test_build_graphiti_uses_compat_reranker(mocker):captured.update(kwargs)mocker.patch("graphiti_core.Graphiti", _FakeGraphiti)- mocker.patch(- "backend.copilot.graphiti.falkordb_driver.AutoGPTFalkorDriver",- MagicMock(),+ mocker.patch.object(+ client_mod,+ "graphiti_config",+ GraphitiConfig.model_construct(+ llm_api_key="k", llm_base_url="https://openrouter.ai/api/v1"+ ),)- client_mod._build_graphiti("user_test", llm_client=MagicMock())+ client_mod._build_graphiti(+ "user_test",+ llm_client=MagicMock(),+ embedder=MagicMock(),+ graph_driver=MagicMock(),+ )++ reranker = captured["cross_encoder"]+ assert isinstance(reranker, CompatOpenAIRerankerClient)+ client, requests = _client_with([_logprob_response("True", -0.1)])+ reranker.client = client++ await reranker.rank("query", ["passage"])- assert isinstance(captured["cross_encoder"], CompatOpenAIRerankerClient)+ assert requests[0]["model"] == "gpt-4.1-mini"diff --git a/docs/platform/copilot-local-llm.md b/docs/platform/copilot-local-llm.mdindex bcfac6ea34..03953c0dc4 100644--- a/docs/platform/copilot-local-llm.md+++ b/docs/platform/copilot-local-llm.md@@ -391,7 +391,7 @@ rewrites the cloud OpenAI defaults to local Ollama equivalents:| Setting | Cloud default | Local default ||---|---|---|| `GRAPHITI_LLM_MODEL` | `gpt-4.1-mini` | `hf.co/ornith-ai/Ornith-1.5-9B-GGUF:Q4_K_M` |-| `GRAPHITI_RERANKER_MODEL` | `gpt-4.1-nano` | `hf.co/ornith-ai/Ornith-1.5-9B-GGUF:Q4_K_M` |+| `GRAPHITI_RERANKER_MODEL` | `gpt-4.1-mini` | `hf.co/ornith-ai/Ornith-1.5-9B-GGUF:Q4_K_M` || `GRAPHITI_EMBEDDER_MODEL` | `text-embedding-3-small` | `nomic-embed-text` |The LLM + reranker reuse the same Ornith 1.5 9B model the `--with-ollama`