.as_retriever() is invalid in Pinecone?

When I use a local Vector DB and FAISS, as_retriever() works fine, but if I try to use an Index I’ve stored on Pinecone, I am unable to feed it into my RetrievalQA chain. This is my code:

pc = Pinecone(api_key = pinecone_api_key)
index = pc.Index(host = host_url)
text_field = 'text' # key of dict that stores the text metadata in the index
vectorstore = Pinecone(index,embeddings = embeddings, text_field = text_field)
 
RetrievalQA.from_chain_type(
            llm=chat,
            chain_type="stuff",
            retriever=vectorstore.as_retriever(),
        )

I am getting the following error:

retriever=vectorstore.as_retriever(),
AttributeError: ‘Pinecone’ object has no attribute ‘as_retriever’

How should I proceed?

I wish to further use Maximal Marginal Separation, I thought this would work, would this is still giving the same error.

retriever = searcher.as_retriever()
retriever.search_kwargs['top_k'] = 25
retriever.search_kwargs['maximal_marginal_relevance'] = True
retriever.search_kwargs['k'] = 15

Looks like you may be using an older version of Langchain, which uses the same name for its vector store object that we do for the Pinecone connection object. Please be sure to update to the latest version of Langchain which uses this format to import and instantiate the Langchain object:

from langchain_pinecone import PineconeVectorStore

index_name = "langchain-test-index"

docsearch = PineconeVectorStore.from_documents(docs, embeddings, index_name=index_name)

Please correct me if I am wrong, but I thought that from_documents was used to add to the VectorStore.

I had already used that when creating the Index.

Now I wanted to access that very Index in a new session, would from_documents still be used?

Right, but from_documents is part of Langchain. Not the Pinecone SDK. Since older versions of Langchain used the same name we do for a different class trying to call Pinecone.from_documents() will fail.

Hello !

I am having the same issue since i tried to use Pinecone as a retreiver this way:

vectorstore = Pinecone(index_name, "combined")

qa = RetrievalQA.from_chain_type(
    llm = llm,
    chain_type = "combined",
    retriever = vectorstore.as_retriever()
    )

i have read to use langchain PineconeVectorStore.from_documents but here is the thing. This function will embed text into vectors and store it in the index, but what happens if I already have the text embedded and I don’t want to re-embed it again and instead to “retreive or fetch” the index vectors and use it as a retreiver. do you know how can i do it ?