# Unable to use Langchain Pinecone from\_texts

**URL:** <https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340>\
**Category:** Support\
**Created:** [January 30, 2024, 1:23pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340 "2024-01-30T13:23:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajsbhatta](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajsbhatta/32/1997_2.png) [@rajsbhatta](https://community.pinecone.io/u/rajsbhatta)\
**Post date:** [January 30, 2024, 1:23pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/1 "2024-01-30T13:23:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Cory\_Pinecone](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/cory_pinecone/32/1712_2.png) [@Cory\_Pinecone](https://community.pinecone.io/u/Cory_Pinecone)\
**Post date:** [January 30, 2024, 6:38pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/2 "2024-01-30T18:38:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rajsbhatta](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajsbhatta/32/1997_2.png) [@rajsbhatta](https://community.pinecone.io/u/rajsbhatta)\
**Post date:** [February 2, 2024, 3:56pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/3 "2024-02-02T15:56:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tim.rennie](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@tim.rennie](https://community.pinecone.io/u/tim.rennie)\
**Post date:** [February 3, 2024, 7:34pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/4 "2024-02-03T19:34:02Z")

</div>

import os  
os.environ[‘PINECONE\_API\_KEY’] = PINECONE\_API\_KEY

This will set the environment variable that is being looked for

---

<div class="post-metadata">

**Author:** ![rajsbhatta](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajsbhatta/32/1997_2.png) [@rajsbhatta](https://community.pinecone.io/u/rajsbhatta)\
**Post date:** [February 4, 2024, 6:04am UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/5 "2024-02-04T06:04:00Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![tim.rennie](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@tim.rennie](https://community.pinecone.io/u/tim.rennie)\
**Post date:** [February 4, 2024, 6:31pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/6 "2024-02-04T18:31:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/pinecone/original/1X/d16664eba369eeee623700cf12feab5562b37eaf.jpeg) [@system](https://community.pinecone.io/u/system)\
**Post date:** [February 5, 2024, 6:31pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/7 "2024-02-05T18:31:21Z")

</div>

Closed on February 5, 2024, 6:31pm UTC

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

---

<div class="post-metadata">

**Author:** ![jocelyn](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/jocelyn/32/1653_2.png) [@jocelyn](https://community.pinecone.io/u/jocelyn)\
**Post date:** [March 18, 2024, 7:37pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/8 "2024-03-18T19:37:11Z")

</div>

Opened on March 18, 2024, 7:37pm UTC



---

<div class="post-metadata">

**Author:** ![shinycaroline.s](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/shinycaroline.s/32/2314_2.png) [@shinycaroline.s](https://community.pinecone.io/u/shinycaroline.s)\
**Post date:** [March 23, 2024, 1:59pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/9 "2024-03-23T13:59:37Z")

</div>

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’.

---

<div class="post-metadata">

**Author:** ![shinycaroline.s](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/shinycaroline.s/32/2314_2.png) [@shinycaroline.s](https://community.pinecone.io/u/shinycaroline.s)\
**Post date:** [March 23, 2024, 2:03pm UTC](https://community.pinecone.io/t/unable-to-use-langchain-pinecone-from-texts/4340/10 "2024-03-23T14:03:13Z")

</div>

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

```
    pc = PineconeClient(api_key=PINECONE_API_KEY)
    index_name = "test-1"
    index = pc.Index(index_name)
    print(index.describe_index_stats())
    embeddings = OpenAIEmbeddings(openai_api_key = OPENAI_API_KEY)
    query = "”        
    docsearch = PineconeLang.from_existing_index(index_name, embeddings, pc)
    docs = docsearch.similarity_search(query, include_metadata=True)
    print(docs)

```

I have kept my pinecone and openAI key in .env only
