Load index using from_texts

Hi there! I’m starting to use Pinecone and I am unable to load an index already created.
Repro steps:

#Load a dataset
from datasets import load_dataset
MedQA_dataset = load_dataset(“GBaker/MedQA-USMLE-4-options”, split=“train+test”)
question = MedQA_dataset[‘question’]
answer = MedQA_dataset[‘answer’]
texts = [str(x) + ’ The answer is:’ + str(y) for x, y in zip(question, answer)]

#Define embedding method
from langchain.embeddings.openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()

#Define vector store
from langchain.vectorstores import Pinecone
import pinecone

api_key=PINECONE_API_KEY, # find at app.pinecone.io
environment=PINECONE_ENV, # next to api key in console
index_name = “yyyyyy”

pinecone = Pinecone.from_texts(texts,embeddings,index_name)

TypeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 tpinecone = Pinecone.from_texts(text_test,embeddings,index_name=“yyyyy”)

19 frames
/usr/lib/python3.10/http/client.py in putheader(self, header, *values)
1257 values[i] = str(one_value).encode(‘ascii’)
→ 1259 if _is_illegal_header_value(values[i]):
1260 raise ValueError(‘Invalid header value %r’ % (values[i],))

TypeError: expected string or bytes-like object

any idea what is happening?


Hey @berni.sira!

What’s happening here is just a parameter ordering problem. The from_texts method from LangChain takes objects like your texts and embeddings as its first and second parameters. The name of your index, though, is actually the method’s 8th parameter. So right now, the Python interpreter is reading your code as

Pinecone.from_texts(texts=texts, embedding=embeddings, metadatas=index_name)

If you simply declare your index_name variable as the value of the index_name parameter explicitly, you should be good to go, e.g.:

Pinecone.from_texts(texts, embeddings, index_name=index_name)

Here’s a preview of what I’m getting on my side w/the change above:

1 Like

oh I see! Thank you so much for taking your time for helping me :slight_smile:

1 Like

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

of course! keep truckin’!