pythonartificial-intelligencechatbotpinecone

Index <pinecone.data.index.Index object at 0x000002655A3E1CD0> does not exist


i kept trying and getting index not exisit even i hve the same index in my pinecone account but still facing same isssue


i kept trying and getting index not exisit even i hve the same index in my pinecone account but still facing same isssue 

from langchain import PromptTemplate
from langchain.chains import RetrievalQA
from langchain.embeddings import huggingface,HuggingFaceEmbeddings
from langchain.vectorstores import Pinecone
import pinecone
from langchain.embeddings import OpenAIEmbeddings
from pinecone import Pinecone
from langchain.document_loaders import PyPDFLoader,DirectoryLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain import text_splitter
from langchain.prompts import PromptTemplate
from langchain.llms import CTransformers```

#etract data from pdf def load_pdf(data): loader= DirectoryLoader(data,glob="*.pdf",loader_cls=PyPDFLoader) documents=loader.load() return documents

extracted_data=load_pdf("data/")

def text_split(extracted_data): text_splitter=RecursiveCharacterTextSplitter(chunk_size=500,chunk_overlap=20) text_chunk=text_splitter.split_documents(extracted_data) return text_chunk```

text_chunks=text_split(extracted_data)
print("length of my chunk :" ,len(text_chunks))

embeddings=download_hugging_face_embeddings()


query_result=embeddings.embed_query("hello world")
print("length",len(query_result))

#i kept trying and getting index not exisit even i hve the same #index in my pinecone account but still facing same isssue 

from pinecone import Pinecone
from langchain.vectorstores import Pinecone as PC
from langchain.vectorstores import Pinecone as PineconeVectorStore
# initialize connection to pinecone (get API key at app.pinecone.io)
api_key = API_KEY

pc = Pinecone(api_key=api_key)
index_name =pc.Index("medical-chatbot")

pc.list_indexes()
docsearch = PineconeVectorStore(
    index_name, embeddings, [t.page_content for t in text_chunks]
)

pc = Pinecone(api_key=api_key)
index_name =pc.Index("medical-chatbot")
docsearch=Pinecone.from_existing_index(index_name, embeddings)

query = "What are Allergies"

docs=docsearch.similarity_search(query, k=3)

print("Result", docs)

Solution

  • langchain.vectorstores has been deprecated.

    To update/intall the packages run the following command in terminal

    %pip install --upgrade --quiet  langchain-pinecone langchain-openai langchain
    

    Update your code like this:

    import os
    os.environ["OPENAI_API_KEY"] = "api-key"
    os.environ["PINECONE_API_KEY"] = "pinecone-key"
    
    from langchain.text_splitter import CharacterTextSplitter
    from langchain_community.document_loaders import PyPDFLoader
    from langchain_openai import OpenAIEmbeddings
    
    loader = PyPDFLoader("beyond-good-and-evil.pdf")
    documents = loader.load()
    text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
    docs = text_splitter.split_documents(documents)
    # print(docs)
    
    embeddings = OpenAIEmbeddings()
    
    from langchain_pinecone import PineconeVectorStore
    
    index_name = "companion"
    
    docsearch = PineconeVectorStore.from_documents(docs, embeddings, index_name=index_name)
    
    query = "What is the meaning life??"
    docs = docsearch.similarity_search(query)
    print(docs[0].page_content)
    

    Results :

    enter image description here