I am facing some difficulties in working with Langchain’s pinecone. Can someone please indicate what mistake i am doing in the below python code ?
PINECONE_API_KEY = “xxxxxxxxxxxx”
INDEX_NAME = “demo1”
OPENAI_API_KEY = “xxxxxxxxxxxx”
import os
import openai
from langchain_openai import OpenAIEmbeddings
from pinecone import Pinecone as PineconeClient
from langchain_community.vectorstores import Pinecone as PineconeLang
Thanks much @tim.rennie
It is working now. If you don’t mind, can you please suggest why my code wasn’t working when I had mentioned the key directly in my code (see the first line)?
All I can say is that the langchain class in python is using that method to look for the credentials. Seems counterintuitive, but that is how it is programmed for the from_documents class.
Can you help me too? I am able to see my vectors in hosted application but when I try to retrieve it using the function Pinecone.from_existing_index(), and this is where I am getting some error :Traceback (most recent call last):
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\django\core\handlers\exception.py”, line 55, in inner
response = get_response(request)
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\django\core\handlers\base.py”, line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\django\views\decorators\csrf.py”, line 56, in wrapper_view
return view_func(*args, **kwargs)
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\django\views\generic\base.py”, line 104, in view
return self.dispatch(request, *args, **kwargs)
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\rest_framework\views.py”, line 509, in dispatch
response = self.handle_exception(exc)
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\rest_framework\views.py”, line 469, in handle_exception
self.raise_uncaught_exception(exc)
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\rest_framework\views.py”, line 480, in raise_uncaught_exception
raise exc
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\rest_framework\views.py”, line 506, in dispatch
response = handler(request, *args, **kwargs)
File “C:\Users\user\Project\nudge2edge\Project Momentum\rag\rag_pinecone.py”, line 26, in get
docsearch = PineconeLang.from_existing_index(index_name, embeddings, pc)
File “C:\Users\user\Project\nudge2edge\backendenv\lib\site-packages\langchain\vectorstores\pinecone.py”, line 410, in from_existing_index
return cls(pinecone.Index(index_name), embedding, text_key, namespace)
TypeError: Index.init() missing 1 required positional argument: ‘host’.
Here is my code.
from langchain.embeddings import OpenAIEmbeddings
from nudge2edge_prototype.settings import OPENAI_API_KEY,PINECONE_API_KEY
from pinecone import Pinecone as PineconeClient
from langchain.vectorstores import Pinecone as PineconeLang