Skip to content

Commit 6937e7f

Browse files
authored
chore: clarify sbert/ for local models & simplify trust_remote_code (#60)
the original concern comes from #56
1 parent abd8afd commit 6937e7f

4 files changed

Lines changed: 15 additions & 55 deletions

File tree

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,20 @@ claude mcp add cocoindex-code \
263263

264264
Any model supported by LiteLLM works — see the [full list of embedding providers](https://docs.litellm.ai/docs/embedding/supported_embedding).
265265

266-
### GPU-optimised local model
266+
### Local SentenceTransformers models
267267

268-
If you have a GPU, [`nomic-ai/CodeRankEmbed`](https://huggingface.co/nomic-ai/CodeRankEmbed) delivers significantly better code retrieval than the default model. It is 137M parameters, requires ~1 GB VRAM, and has an 8192-token context window.
268+
Use the `sbert/` prefix to load any [SentenceTransformers](https://www.sbert.net/) model locally (no API key required).
269+
270+
**Example — general purpose text model:**
271+
```bash
272+
claude mcp add cocoindex-code \
273+
-e COCOINDEX_CODE_EMBEDDING_MODEL=sbert/nomic-ai/nomic-embed-text-v1 \
274+
-- cocoindex-code
275+
```
276+
277+
**GPU-optimised code retrieval:**
278+
279+
[`nomic-ai/CodeRankEmbed`](https://huggingface.co/nomic-ai/CodeRankEmbed) delivers significantly better code retrieval than the default model. It is 137M parameters, requires ~1 GB VRAM, and has an 8192-token context window.
269280

270281
```bash
271282
claude mcp add cocoindex-code \

src/cocoindex_code/config.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class Config:
7676
embedding_model: str
7777
index_dir: Path
7878
device: str | None
79-
trust_remote_code: bool
8079
extra_extensions: dict[str, str | None]
8180
excluded_patterns: list[str]
8281

@@ -103,16 +102,6 @@ def from_env(cls) -> Config:
103102
# Device: auto-detect CUDA or use env override
104103
device = os.environ.get("COCOINDEX_CODE_DEVICE")
105104

106-
# trust_remote_code: opt-in via env var only.
107-
# sentence-transformers 5.x+ supports Jina models natively, so
108-
# auto-enabling this for jinaai/ models causes failures with
109-
# transformers 5.x (removed find_pruneable_heads_and_indices).
110-
trust_remote_code = os.environ.get("COCOINDEX_CODE_TRUST_REMOTE_CODE", "").lower() in (
111-
"1",
112-
"true",
113-
"yes",
114-
)
115-
116105
# Extra file extensions (format: "inc:php,yaml,toml" — optional lang after colon)
117106
raw_extra = os.environ.get("COCOINDEX_CODE_EXTRA_EXTENSIONS", "")
118107
extra_extensions: dict[str, str | None] = {}
@@ -134,7 +123,6 @@ def from_env(cls) -> Config:
134123
embedding_model=embedding_model,
135124
index_dir=index_dir,
136125
device=device,
137-
trust_remote_code=trust_remote_code,
138126
extra_extensions=extra_extensions,
139127
excluded_patterns=excluded_patterns,
140128
)

src/cocoindex_code/shared.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@
3131
# Models that define a "query" prompt for asymmetric retrieval.
3232
_QUERY_PROMPT_MODELS = {"nomic-ai/nomic-embed-code", "nomic-ai/CodeRankEmbed"}
3333
query_prompt_name: str | None = "query" if _model_name in _QUERY_PROMPT_MODELS else None
34-
# Models whose custom remote code is known-compatible with transformers 5.x.
35-
_KNOWN_REMOTE_CODE_MODELS = {"nomic-ai/CodeRankEmbed"}
36-
_trust = config.trust_remote_code or _model_name in _KNOWN_REMOTE_CODE_MODELS
3734
embedder = SentenceTransformerEmbedder(
3835
_model_name,
3936
device=config.device,
40-
trust_remote_code=_trust,
37+
trust_remote_code=True,
4138
)
4239
logger.info(
43-
"Embedding model: %s | device: %s | trust_remote_code: %s",
40+
"Embedding model: %s | device: %s",
4441
config.embedding_model,
4542
config.device,
46-
_trust,
4743
)
4844
else:
4945
from cocoindex.ops.litellm import LiteLLMEmbedder

tests/test_config.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,6 @@ def test_env_var_overrides_device(self, tmp_path: Path) -> None:
3434
config = Config.from_env()
3535
assert config.device == "cpu"
3636

37-
38-
class TestConfigTrustRemoteCode:
39-
"""Tests for trust_remote_code env var control."""
40-
41-
def test_false_by_default(self, tmp_path: Path) -> None:
42-
with patch.dict(
43-
os.environ,
44-
{"COCOINDEX_CODE_ROOT_PATH": str(tmp_path)},
45-
):
46-
os.environ.pop("COCOINDEX_CODE_TRUST_REMOTE_CODE", None)
47-
config = Config.from_env()
48-
assert config.trust_remote_code is False
49-
50-
def test_true_when_env_var_set_to_true(self, tmp_path: Path) -> None:
51-
with patch.dict(
52-
os.environ,
53-
{
54-
"COCOINDEX_CODE_ROOT_PATH": str(tmp_path),
55-
"COCOINDEX_CODE_TRUST_REMOTE_CODE": "true",
56-
},
57-
):
58-
config = Config.from_env()
59-
assert config.trust_remote_code is True
60-
61-
def test_true_when_env_var_set_to_1(self, tmp_path: Path) -> None:
62-
with patch.dict(
63-
os.environ,
64-
{
65-
"COCOINDEX_CODE_ROOT_PATH": str(tmp_path),
66-
"COCOINDEX_CODE_TRUST_REMOTE_CODE": "1",
67-
},
68-
):
69-
config = Config.from_env()
70-
assert config.trust_remote_code is True
71-
7237
def test_default_model_is_minilm(self, tmp_path: Path) -> None:
7338
with patch.dict(
7439
os.environ,

0 commit comments

Comments
 (0)