1

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 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.