Repository navigation
feat(embeddings): optional CUDA device selection and NVIDIA NIM embedding preset - #358
Open
Coding-Dev-Tools wants to merge 5 commits into
Open
Coding-Dev-Tools wants to merge 5 commits into
Coding-Dev-Tools wants to merge 5 commits into
Conversation
…ding preset Add optional CUDA acceleration for local sentence-transformers embeddings and an opt-in NVIDIA NIM preset on the existing OpenAI-compatible ApiEmbedder while keeping default offline CPU behavior 100% unchanged: - Add ENGRAPHIS_EMBED_DEVICE (auto | cpu | cuda | cuda:<index>) resolution in embedder_st.py with safe fallback to CPU when CUDA or torch is unavailable (or actionable RuntimeError under require_exact_backends). - Extend ApiEmbedder with create_nvidia_nim_embedder() preset (default https://integrate.api.nvidia.com/v1, model nvidia/nv-embedqa-e5-v5, NVIDIA_API_KEY / ENGRAPHIS_EMBED_API_KEY, self-hosted NIM base URL via ENGRAPHIS_EMBED_BASE_URL / NVIDIA_NIM_BASE_URL, and asymmetric input_type query/passage + truncate handling). - Forward input_type="query" vs "passage" through core/interfaces.py embed_texts() without breaking existing Embedder implementations. - Enforce remote privacy guards so sensitivity="secret" memories are never transmitted to remote embedding APIs during writes or rebuilds, while preserving existing versioned embedding-space rebuild and dimension mismatch protections. - Document env vars, examples, and privacy notes in docs/CONFIGURATION.md, docs/LLM_PROVIDERS.md, and .env.example, add mocked unit tests in tests/test_nvidia_embeddings.py, and refresh the offline benchmark evidence artifact.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Owner
Author
2-Agent Independent Review & Verification Summary (Head
|
Three defects in the NVIDIA NIM embedding work:
* `_select_api_provider()` consulted `ENGRAPHIS_EMBED_PROVIDER` before
exempting the `local:` prefix or an explicit `provider="local"`. With
`ENGRAPHIS_EMBED_PROVIDER=nvidia-nim`, `get_embedder("local:...")` was
routed to the remote API, so scripts/importer.py's offline import guard
sent local document text and a bogus "local:..." model id to NIM.
Honor `local:` and explicit local providers first, and reject an
unknown explicit provider when require_exact is set.
* `correct()`, `approve()`, and `_merge_locked()` rewrote
`memories.sensitivity` from the column alone. Legacy rows keep the
secret flag in metadata, so finalizing reset them to 'normal' and
`SyncEngine.export_workspace()` (which filters on sensitivity !=
'secret') then exported them. Fold `is_secret_memory()` into every
finalizer and into the merge sensitivity lattice.
* `is_secret_memory()` matched only the literal 'secret', failing open
on labels such as 'restricted' or 'confidential'. Apply the
{"normal", "sensitive"} allowlist the rest of the codebase already
uses so unknown labels fail closed.
`tests/test_benchmark_evidence.py` hashes every `.py` under `engraphis/` and `eval/`, so the embedder_st, engine, and interfaces changes invalidated the committed registry artifact and failed the whole Python matrix. Export a new immutable artifact and repoint the test constants, README prefix, BENCHMARKS.md name/sha, and the fixture-suite digest. The SVGs and PNGs were regenerated so their embedded provenance matches.
This branch has not been deployed
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 optional NVIDIA CUDA device selection for local
sentence-transformersembeddings and an opt-in NVIDIA NIM embeddings preset on the existing OpenAI-compatibleApiEmbedder, without changing Engraphis's default offline/CPU behavior.What changed & why
engraphis/backends/embedder_st.py,engraphis/config.py,engraphis/factory.py,engraphis/service.py):ENGRAPHIS_EMBED_DEVICE(auto|cpu|cuda|cuda:<index>) andresolve_embed_device().torchimport, nodevicekwarg passed toSentenceTransformer).autoselectscudawhentorch.cuda.is_available()is true and falls back cleanly tocpuon CPU-only/PyTorch-free installs. Explicitcuda/cuda:<index>falls back tocpuwith a warning unlessrequire_exact_backends=True, in which case an actionable error is raised.engraphis/backends/embedder_api.py,engraphis/backends/embedder_st.py):ApiEmbedder(no duplicate backend module) withcreate_nvidia_nim_embedder()and factory routing forENGRAPHIS_EMBED_MODEL=nvidia-nim[:<model>]andENGRAPHIS_EMBED_PROVIDER=nvidia-nim.https://integrate.api.nvidia.com/v1+nvidia/nv-embedqa-e5-v5+NVIDIA_API_KEY(orENGRAPHIS_EMBED_API_KEY), and supports self-hosted NIM viaENGRAPHIS_EMBED_BASE_URL/NVIDIA_NIM_BASE_URL(HTTPS required for non-loopback; loopback self-hosted NIM permits unauthenticated local containers).input_type("passage"on writes/rebuilds/sync,"query"on recall/history/grounded support) andtruncate="END"/encoding_format="float"in both batch and per-item fallback requests via a backward-compatibleembed_texts()helper inengraphis/core/interfaces.py.engraphis/core/engine.py,engraphis/core/recall.py,engraphis/core/grounded.py,engraphis/core/sync.py):reject_secretsbefore embedding and preventssensitivity="secret"memories from being sent to remote embedding APIs during writes and versioned rebuilds (is_remote_embedder()).docs/CONFIGURATION.md,docs/LLM_PROVIDERS.md,.env.example,BENCHMARKS.md,README.md,docs/benchmark-evidence/,docs/images/):offline-fixtures-nvidia-embeddings-20261127.json) and rendered benchmark visuals.Verification
All HTTP and PyTorch interactions in unit tests are mocked (no network, no GPU required):
python -m pytest tests/test_nvidia_embeddings.py tests/test_embeddings.py tests/test_backends_factories.py tests/test_provider_error_redaction.py tests/test_config.py tests/test_grounded.py tests/test_eval_performance_engine.py tests/test_benchmark_evidence.py -q-> PASS (PYTEST_EXIT=0, 268 passed, 1 skipped)python -m ruff check .-> PASS (All checks passed!)python -m pyright --pythonpath .venv/Scripts/python.exe engraphis/core/interfaces.py engraphis/core/engine.py engraphis/core/recall.py engraphis/core/grounded.py engraphis/core/sync.py engraphis/backends/embedder_api.py engraphis/backends/embedder_st.py engraphis/factory.py-> PASS (0 errors, 0 warnings, 0 informations; note local.venvhas a pre-existing partialtransformersinstall causing unrelatedAutoTokenizer/AutoProcessormissing-symbol errors in untouchedextractor.py/eval/harness.pyand an unrelatedImportErrorintests/test_mcp_server.py::test_stdio_first_semantic_tool_call_completes_with_cached_model)python scripts/check_commercial_manifest.py-> PASS (commercial manifest check: OK)python scripts/externalize_dashboard_assets.py-> PASS (exit 0)sample.jsonl,codemem.jsonl,ablation,reinforcement,adversarial_memory_security,grounded,code_arm,spec_crawl,evidence_contracts) -> PASS (exit 0each)media_gate.pyon regenerateddocs/images/context-efficiency.pnganddocs/images/evidence-backed-agent-examples.png-> PASSNeeds 2 fresh reviewers before merge.