Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Pinecone has no attribute 'from_texts' #388

Closed
2 tasks done
Mukku27 opened this issue Sep 4, 2024 · 5 comments
Closed
2 tasks done

[Bug] Pinecone has no attribute 'from_texts' #388

Mukku27 opened this issue Sep 4, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Mukku27
Copy link

Mukku27 commented Sep 4, 2024


  • I believe this is a new bug
  • I have searched the existing Github issues and Community Forum, and I could not find an existing post for this bug

Describe the bug
When attempting to create an embedding using Pinecone in a Google Colab notebook, an AttributeError is raised. The functionality that was working previously to generate embeddings from text chunks is now broken.

Error information
The full stack trace of the error is as follows:

AttributeError                            Traceback (most recent call last)
<ipython-input-18-dbd3c6635021> in <cell line: 8>()
      6 
      7 #creating Embedding for each of the text Chunk & storing
----> 8 docsearch=pinecone.from_texts([t.page_cont
This should effectively communicate the issue you encountered using the provided bug report template.ent for t in text_chunks],embedding,index_name=index_name)

/usr/local/lib/python3.10/dist-packages/pinecone/control/pinecone.py in from_texts(*args, **kwargs)
    700     @staticmethod
    701     def from_texts(*args, **kwargs):
--> 702         raise AttributeError(_build_langchain_attribute_error_message("from_texts"))
    703 
    704     @staticmethod

AttributeError: from_texts is not a top-level attribute of the Pinecone class provided Pinecone has no attribute 'from_texts'
by pinecone's official python package developed at https://github.com/pinecone-io/pinecone-python-client. You may have a name collision with an export from another dependency in your project that wraps Pinecone functionality and exports a similarly named class. Please refer to the following knowledge base article for more information: https://docs.pinecone.io/troubleshooting/pinecone-attribute-errors-with-langchain

Steps to reproduce the issue locally

  1. Run a Google Colab notebook.
  2. Install the necessary packages, including Pinecone and any dependencies related to LangChain.
  3. Attempt to create an embedding with the following code snippet:
    docsearch = pinecone.from_texts([t.page_content for t in text_chunks], embedding, index_name=index_name)
  4. The error occurs when executing this code.

Environment

  • OS Version: Google Colab (Linux-based)
  • Python version: 3.10
  • Python SDK version: Pinecone Python Client from pinecone-io/pinecone-python-client (latest version installed via pip)

Additional context
The issue seems to be related to a name collision between Pinecone's from_texts method and another dependency that might be wrapping Pinecone functionality. I am using the notebook environment in Google Colab, and a screenshot of the error is attached for reference.


@Mukku27 Mukku27 added the bug Something isn't working label Sep 4, 2024
@github-actions github-actions bot added the status:needs-triage An issue that needs to be triaged by the Pinecone team label Sep 4, 2024
@anawishnoff anawishnoff removed the status:needs-triage An issue that needs to be triaged by the Pinecone team label Sep 6, 2024
@mcpaddy
Copy link

mcpaddy commented Sep 6, 2024

@Mukku27 Thank you for raising this issue.

The Python Pinecone SDK does not have the function from_text() that's usually provided by Langchain. There was an issue when using an older version of Langchain where there could be a Python namespace name collision, so I would ensure that it is up to date and you have made the code changes,

If you can share the code or the Colab, we can help you further.

You might also find our Langchain guide. useful too

@Mukku27
Copy link
Author

Mukku27 commented Sep 7, 2024

Screenshot from 2024-09-07 15-26-21

@Mukku27
Copy link
Author

Mukku27 commented Sep 7, 2024

This is one cell of the whole notebook

@mcpaddy
Copy link

mcpaddy commented Sep 9, 2024

Thank you for the code. Unfortunately, it's incorrect. As I mentioned previously, Pinecone does not have a from_text function. It comes from Langchain.

Here is the correct way to use from_texts() from Langchain.

    import os
    from langchain_pinecone import PineconeVectorStore
    from langchain_openai import OpenAIEmbeddings
    from langchain_community.document_loaders import TextLoader
    from langchain_text_splitters import CharacterTextSplitter

    os.environ['OPENAI_API_KEY'] = '<YOUR_OPENAI_API_KEY>'
    os.environ['PINECONE_API_KEY'] = '<YOUR_PINECONE_API_KEY>'

    index_name = "<YOUR_PINECONE_INDEX_NAME>"
    embeddings = OpenAIEmbeddings()

    texts = ["Tonight, I call on the Senate to: Pass the Freedom to Vote Act.", "ne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court.", "One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence."]

    vectorstore_from_texts = PineconeVectorStore.from_texts(
        texts,
        index_name=index_name,
        embedding=embeddings
    )

There are examples in our Langchain guide.

@Mukku27
Copy link
Author

Mukku27 commented Sep 9, 2024

Thank you @mcpaddy

@Mukku27 Mukku27 closed this as completed Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants