Unable to use Langchain Pinecone from_texts

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

pc = PineconeClient(api_key=PINECONE_API_KEY)

embedding = OpenAIEmbeddings(openai_api_key = OPENAI_API_KEY)

my_note = PineconeLang.from_texts(texts= “abcdefgh”,embedding = embedding, index_name = INDEX_NAME)

print(type(my_note))

I am getting an error -
pinecone.exceptions.PineconeConfigurationError: You haven’t specified an Api-Key.

Where do I need to specify the API-Key?

Hi @rajsbhatta, can you share the full stacktrace of the error? Just to make sure we have all of the relevant context.

Hi @Cory_Pinecone ,
Thanks for your reply. Below is the error from the terminal -

Traceback (most recent call last):
File “D:\AI\dummy.py”, line 16, in
my_note = PineconeLang.from_texts(texts= “abcdefgh”,embedding = embedding, index_name = INDEX_NAME)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “…Python311\site-packages\langchain_community\vectorstores\pinecone.py”, line 438, in from_texts
pinecone_index = cls.get_pinecone_index(index_name, pool_threads)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “…Python311\site-packages\langchain_community\vectorstores\pinecone.py”, line 369, in get_pinecone_index
pinecone_instance = pinecone.Pinecone(
^^^^^^^^^^^^^^^^^^
File “…Python311\site-packages\pinecone\control\pinecone.py”, line 95, in init
self.config = PineconeConfig.build(api_key=api_key, host=host, additional_headers=additional_headers, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “…Python311\site-packages\pinecone\config\pinecone_config.py”, line 12, in build
return ConfigBuilder.build(api_key=api_key, host=host, additional_headers=additional_headers, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “…Python311\site-packages\pinecone\config\config.py”, line 45, in build
raise PineconeConfigurationError(“You haven’t specified an Api-Key.”)
pinecone.exceptions.PineconeConfigurationError: You haven’t specified an Api-Key.

import os
os.environ[‘PINECONE_API_KEY’] = PINECONE_API_KEY

This will set the environment variable that is being looked for

1 Like

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.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.