-
Notifications
You must be signed in to change notification settings - Fork 10
add NVIDIA NIM support with embedder and LLM providers #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ anthropic = ["anthropic>=0.20", "voyageai>=0.2"] | |
| sentence-transformers = ["sentence-transformers>=2.6"] | ||
| bge = ["FlagEmbedding>=1.2"] | ||
| litellm = ["litellm>=1.30"] | ||
| nvidia = ["openai>=1.12"] # NVIDIA NIM uses OpenAI-compatible API | ||
|
Comment on lines
35
to
+43
|
||
| dev = [ | ||
| "pytest>=8.0", | ||
| "pytest-asyncio>=0.23", | ||
|
|
@@ -57,6 +58,7 @@ all = [ | |
| "sentence-transformers>=2.6", | ||
| "FlagEmbedding>=1.2", | ||
| "litellm>=1.30", | ||
| "openai>=1.12", # NVIDIA NIM support | ||
| ] | ||
|
|
||
| [project.scripts] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,3 +65,10 @@ def test_create_anthropic_llm(): | |
| def test_unknown_llm_provider_raises(): | ||
| with pytest.raises(ValueError, match="Unknown LLM provider"): | ||
| create_llm("nonexistent:model") | ||
|
|
||
| def test_create_nvidia_embedder_default_model(): | ||
| from vektori.models.nvidia import NvidiaEmbedder, DEFAULT_EMBEDDING_MODEL | ||
|
|
||
| embedder = create_embedder("nvidia") | ||
| assert isinstance(embedder, NvidiaEmbedder) | ||
| assert embedder.model == DEFAULT_EMBEDDING_MODEL # "nvidia/llama-nemotron-embed-1b-v2" | ||
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,301 @@ | ||||||||||
| """NVIDIA NIM embedding and LLM providers. | ||||||||||
|
|
||||||||||
| NVIDIA NIM (NVIDIA Inference Microservices) provides GPU-optimized models | ||||||||||
| for embedding and text generation via an OpenAI-compatible API. | ||||||||||
|
|
||||||||||
| Get API key: https://build.nvidia.com | ||||||||||
|
|
||||||||||
| Usage: | ||||||||||
| v = Vektori( | ||||||||||
| embedding_model="nvidia:llama-nemotron-embed-1b-v2", | ||||||||||
| extraction_model="nvidia:llama-3.3-nemotron-super-49b-v1", | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| Environment: | ||||||||||
| NVIDIA_API_KEY - Your NVIDIA API key (required) | ||||||||||
|
|
||||||||||
| Models: | ||||||||||
| Embeddings (llama-nemotron-embed-1b-v2 is recommended default): | ||||||||||
| - llama-nemotron-embed-1b-v2: 2048 dim, 8192 tokens, multilingual, Matryoshka | ||||||||||
| - llama-3.2-nv-embedqa-1b-v2: 2048 dim, 8192 tokens, QA-optimized | ||||||||||
| - baai/bge-m3: 1024 dim, 8192 tokens, multilingual, dense+sparse+multi-vector | ||||||||||
| - nv-embed-v1: 4096 dim, 32k tokens, generalist | ||||||||||
| - nv-embedqa-e5-v5: 1024 dim, 512 tokens, fast | ||||||||||
|
|
||||||||||
| LLMs: | ||||||||||
| - llama-3.3-nemotron-super-49b-v1: High quality extraction (default) | ||||||||||
| - llama-3.1-nemotron-ultra-253b-v1: Largest NVIDIA model | ||||||||||
| - nemotron-4-mini-hindi-4b-instruct: Fast, efficient | ||||||||||
| - z-ai/glm5: GLM-5, multilingual LLM | ||||||||||
| - z-ai/glm4.7: GLM-4.7, multilingual LLM | ||||||||||
| - google/gemma-4-31b-it: Google's Gemma 4 31B instruction tuned | ||||||||||
| - minimaxai/minimax-m2.7: MiniMax M2.7 model | ||||||||||
| - moonshotai/kimi-k2.5: Moonshot Kimi K2.5 | ||||||||||
| - moonshotai/kimi-k2-instruct: Moonshot Kimi K2 instruction | ||||||||||
| - deepseek-ai/deepseek-v3.1: DeepSeek V3.1 | ||||||||||
| - qwen/qwen3-coder-480b-a35b-instruct: Qwen3 Coder 480B | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| from __future__ import annotations | ||||||||||
|
|
||||||||||
| import logging | ||||||||||
| import os | ||||||||||
| from typing import Any | ||||||||||
|
|
||||||||||
| from vektori.models.base import EmbeddingProvider, LLMProvider | ||||||||||
|
|
||||||||||
| logger = logging.getLogger(__name__) | ||||||||||
|
|
||||||||||
| NVIDIA_BASE_URL = "https://integrate.api.nvidia.com/v1" | ||||||||||
|
|
||||||||||
| # Embedding dimensions for known NVIDIA models | ||||||||||
| # Matryoshka models support multiple dimensions; max is shown | ||||||||||
| EMBEDDING_DIMENSIONS = { | ||||||||||
| # Nemotron family (Matryoshka: 384, 512, 768, 1024, 2048) | ||||||||||
| "nvidia/llama-nemotron-embed-1b-v2": 2048, | ||||||||||
| "nvidia/llama-nemotron-embed-vl-1b-v2": 2048, | ||||||||||
| # NeMo Retriever family (Matryoshka: 384, 512, 768, 1024, 2048) | ||||||||||
| "nvidia/llama-3.2-nv-embedqa-1b-v2": 2048, | ||||||||||
| "nvidia/llama-3.2-nv-embedqa-1b-v1": 2048, | ||||||||||
| "nvidia/llama-3.2-nemoretriever-300m-embed-v2": 1024, | ||||||||||
| "nvidia/llama-3.2-nemoretriever-300m-embed-v1": 1024, | ||||||||||
| "nvidia/llama-3.2-nemoretriever-1b-vlm-embed-v1": 2048, | ||||||||||
| # BAAI BGE-M3 (hosted on NVIDIA NIM) | ||||||||||
| "baai/bge-m3": 1024, | ||||||||||
| # Other models | ||||||||||
| "nvidia/nv-embed-v1": 4096, | ||||||||||
| "nvidia/nv-embedqa-e5-v5": 1024, | ||||||||||
| "nvidia/nv-embedcode-7b-v1": 4096, | ||||||||||
| "nvidia/nv-embedqa-e5-v4": 1024, | ||||||||||
| "nvidia/nvclip": 512, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Models that support Matryoshka embeddings (configurable dimensions) | ||||||||||
| MATRYOSHKA_MODELS = { | ||||||||||
| "nvidia/llama-nemotron-embed-1b-v2", | ||||||||||
| "nvidia/llama-nemotron-embed-vl-1b-v2", | ||||||||||
| "nvidia/llama-3.2-nv-embedqa-1b-v2", | ||||||||||
| "nvidia/llama-3.2-nv-embedqa-1b-v1", | ||||||||||
| } | ||||||||||
|
|
||||||||||
| DEFAULT_EMBEDDING_MODEL = "nvidia/llama-nemotron-embed-1b-v2" | ||||||||||
| DEFAULT_LLM_MODEL = "nvidia/llama-3.3-nemotron-super-49b-v1" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class NvidiaEmbedder(EmbeddingProvider): | ||||||||||
| """NVIDIA NIM embedding models via OpenAI-compatible API. | ||||||||||
|
|
||||||||||
| Supports all NVIDIA embedding models including: | ||||||||||
| - llama-nemotron-embed-1b-v2 (recommended): multilingual, 2048-dim, Matryoshka | ||||||||||
| - llama-3.2-nv-embedqa-1b-v2: QA-optimized, 2048-dim, Matryoshka | ||||||||||
| - nv-embed-v1: generalist, 4096-dim, 32k context | ||||||||||
| - nv-embedqa-e5-v5: fast, 1024-dim, 512 context | ||||||||||
|
|
||||||||||
| Matryoshka models support configurable output dimensions: | ||||||||||
| 384, 512, 768, 1024, or 2048. Use the dimensions parameter or | ||||||||||
| embedding_dimension config to set custom dimensions. | ||||||||||
|
Comment on lines
+95
to
+96
|
||||||||||
| 384, 512, 768, 1024, or 2048. Use the dimensions parameter or | |
| embedding_dimension config to set custom dimensions. | |
| 384, 512, 768, 1024, or 2048. Use the dimensions parameter to | |
| set custom dimensions. |
Copilot
AI
Apr 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input_type is hard-coded to "passage" for models that distinguish between indexing (passage) vs querying (query). Vektori uses the same embedder for both ingestion and retrieval queries, so this will also embed user queries as "passage" and can degrade retrieval quality for asymmetric models. Consider making input_type configurable (e.g., constructor arg) and/or exposing separate methods/instances for passage vs query embeddings.
Copilot
AI
Apr 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generate() retries without response_format on any exception. This can mask real failures (auth/rate limit/network) and can double-request/cost on transient errors. Prefer only falling back for the specific "response_format not supported"/400-type error (similar to the GitHub provider’s pattern) and re-raise unexpected exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README suggests
embedding_dimension=1024will control NVIDIA Matryoshka output size, but the current code path (Vektori->create_embedder) doesn’t passembedding_dimensionintoNvidiaEmbedder(dimensions=...). Either update the wiring so this example works as written, or adjust the docs to show how to set dimensions (e.g., via provider kwargs/config).