AttributeError: 'Pinecone' object has no attribute 'from_texts'

349 views Asked by At

I am trying to create embeddings for the chunk text which I have created, but when I try to use the method from_texts, i am getting the following error

AttributeError: 'Pinecone' object has no attribute 'from_texts'

This is my code.

model_name = "sentence-transformers/all-mpnet-base-v2"
model_kwargs = {'device': 'cpu'}
encode_kwargs = {'normalize_embeddings': False}
hf = HuggingFaceEmbeddings(
    model_name=model_name,
    model_kwargs=model_kwargs,
    encode_kwargs=encode_kwargs
)

pc = Pinecone(api_key=pinecone_api_key)
pc.Index=pinecone_index
pc.from_texts([t.page_content for t in text_chunks],hf,pinecone_index)

Is this method got depreceated? what is the alternate method for this

2

There are 2 answers

0
Daniel Perez Efremova On

Problem

Seems that you are using a not suitable Pinecone object.

Solution

If you are looking for a .from_text method, import Pinecone from langchain

from langchain.vectorstores import Pinecone as PC

docs_chunks = [t.page_content for t in text_chunks]
pinecone_index = PC.from_texts(
    docs_chunks,
    hf,
    index_name='your-index-name'
)

Extra Ball

Similar problem in the Pinecone community site: https://community.pinecone.io/t/pinecone-from-texts-not-working/4149/3

1
djilali faycal On

use this methode i tried and its worked for me

from pinecone import Pinecone
pc = Pinecone(api_key="your api_key")  

 
index_name="your index name"
index = pc.Index(index_name)  
for i, t in zip(range(len(text_chunks)), text_chunks):
   query_result = embeddings.embed_query(t.page_content)
   index.upsert(
   vectors=[
        {
            "id": str(i),  # Convert i to a string
            "values": query_result, 
            "metadata": {"text":str(text_chunks[i].page_content)} # meta data as dic
        }
    ],
    namespace="real" 
)

    index.describe_index_stats()