Skip to content

Fix rag lagchain with local nim #287

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions RAG/notebooks/langchain/RAG_Langchain_with_Local_NIM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"!pip install --upgrade pip\n",
"!pip install langchain==0.2.5\n",
"!pip install langchain-nvidia-ai-endpoints==0.1.2\n",
"!pip install faiss-gpu==1.7.2 # replace with faiss-cpu if you don't have a gpu"
"!pip install faiss-gpu==1.7.2 # replace with faiss-cpu if you don't have a gpu\n",
"!pip install langchain-core==0.2.6 langchain-community"
]
},
{
Expand All @@ -152,6 +153,36 @@
" os.environ[\"NVIDIA_API_KEY\"] = nvapi_key"
]
},
{
"cell_type": "markdown",
"id": "15e9c168",
"metadata": {},
"source": [
"Configure the model options"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a8692b6",
"metadata": {},
"outputs": [],
"source": [
"chat_model_options = {\n",
" \"base_url\": \"http://0.0.0.0:8000/v1\",\n",
" \"model\": \"meta/llama3-8b-instruct\",\n",
" \"temperature\": 0.1,\n",
" \"max_tokens\": 1000,\n",
" \"top_p\": 1.0\n",
"}\n",
"\n",
"embeddings_model_options = {\n",
" \"base_url\": \"http://0.0.0.0:8000/v1\",\n",
" \"model\": \"NV-Embed-QA\",\n",
" \"truncate\": \"END\"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "5584e3b1",
Expand All @@ -169,7 +200,7 @@
"source": [
"from langchain_nvidia_ai_endpoints import ChatNVIDIA\n",
"\n",
"llm = ChatNVIDIA(base_url=\"http://0.0.0.0:8000/v1\", model=\"meta/llama3-8b-instruct\", temperature=0.1, max_tokens=1000, top_p=1.0)\n",
"llm = ChatNVIDIA(**chat_model_options)\n",
"\n",
"result = llm.invoke(\"What is the capital of France?\")\n",
"print(result.content)"
Expand Down Expand Up @@ -342,7 +373,7 @@
" Returns:\n",
" None\n",
" \"\"\"\n",
" embeddings = NVIDIAEmbeddings(model=\"NV-Embed-QA\", truncate=\"END\")\n",
" embeddings = NVIDIAEmbeddings(**embedding_model_options)\n",
"\n",
" for document in documents:\n",
" texts = splitter.split_text(document.page_content)\n",
Expand Down Expand Up @@ -378,11 +409,9 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"create_embeddings()\n",
"\n",
"embedding_model = NVIDIAEmbeddings(model=\"NV-Embed-QA\", truncate=\"END\")\n"
"embedding_model = NVIDIAEmbeddings(**embedding_options)\n"
]
},
{
Expand Down Expand Up @@ -420,7 +449,7 @@
"metadata": {},
"outputs": [],
"source": [
"llm = ChatNVIDIA(base_url=\"http://0.0.0.0:8000/v1\", model=\"meta/llama3-8b-instruct\", temperature=0.1, max_tokens=1000, top_p=1.0)\n",
"llm = ChatNVIDIA(**chat_model_options)\n",
"\n",
"memory = ConversationBufferMemory(memory_key=\"chat_history\", return_messages=True)\n",
"\n",
Expand Down