NVIDIA AI Endpoints for LangChain
This integration package connects NVIDIA AI Endpoints with the LangChain framework, providing seamless access to NVIDIA's state-of-the-art AI Foundation Models. It enables robust conversational AI and semantic embedding capabilities through classes like `ChatNVIDIA` and `NVIDIAEmbeddings`. Currently at version 1.2.1, the library maintains an active development pace with frequent updates.
Warnings
- breaking With the release of LangChain 1.0, the broader LangChain ecosystem underwent significant changes, streamlining its core and moving some legacy functionality to `langchain-classic`. While `langchain-nvidia-ai-endpoints` adapted, ensure your overall `langchain` and `langchain-core` dependencies are compatible.
- gotcha Incorrect or missing `NVIDIA_API_KEY` will lead to authentication failures. The key must start with `nvapi-`.
- gotcha Using older versions of `langchain-nvidia-ai-endpoints` with newer NVIDIA AI Foundation Models may result in uninformative errors or lack of support for latest model features. For example, specific models might require a minimum package version.
- gotcha When self-hosting NVIDIA NIM microservices, incorrect `base_url` or port configuration for models like `NVIDIARAGRetriever` can lead to `NVIDIARAGConnectionError`.
Install
-
pip install langchain-nvidia-ai-endpoints
Imports
- ChatNVIDIA
from langchain_nvidia_ai_endpoints import ChatNVIDIA
- NVIDIAEmbeddings
from langchain_nvidia_ai_endpoints import NVIDIAEmbeddings
- NVIDIARerank
from langchain_nvidia_ai_endpoints import NVIDIARerank
- ChatNVIDIADynamo
from langchain_nvidia_ai_endpoints import ChatNVIDIADynamo
- NVIDIARAGRetriever
from langchain_nvidia_ai_endpoints import NVIDIARAGRetriever
Quickstart
import os
from langchain_nvidia_ai_endpoints import ChatNVIDIA, NVIDIAEmbeddings
nvapi_key = os.environ.get('NVIDIA_API_KEY', '')
if not nvapi_key.startswith('nvapi-'):
print("Please set the NVIDIA_API_KEY environment variable. You can get one from the NVIDIA API Catalog.")
else:
# Initialize ChatNVIDIA for conversational AI
chat_model = ChatNVIDIA(model="nvidia/nemotron-3-super-120b-a12b", nvidia_api_key=nvapi_key)
chat_response = chat_model.invoke("Explain the concept of large language models.")
print("Chat Model Response:", chat_response.content)
# Initialize NVIDIAEmbeddings for semantic embeddings
embed_model = NVIDIAEmbeddings(model="nvolveqa_40k", nvidia_api_key=nvapi_key)
embedding_output = embed_model.embed_query("What are vector embeddings?")
print("Embedding Model Output Length:", len(embedding_output))