docsearch=PV.from_texts([t.page_content for t in text_chunks], embeddings, index_name=index_name)
I don’t know why this is showing i tried a lot solving this and yesterday when i was practicing it was perfectly working . below is my whole code
print("hii")
from langchain import PromptTemplate
from langchain.chains import RetrievalQA
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import Pinecone as PV
from pinecone import Pinecone
from langchain.document_loaders import PyPDFLoader, DirectoryLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.prompts import PromptTemplate
from langchain.llms import CTransformers
#Extract data from the PDF
def load_pdf(data):
loader = DirectoryLoader(data,
glob="*.pdf",
loader_cls=PyPDFLoader)
documents = loader.load()
return documents
extracted_data = load_pdf("data/")
extracted_data
#Create text chunks
def text_split(extracted_data):
text_splitter = RecursiveCharacterTextSplitter(chunk_size = 50, chunk_overlap = 10)
text_chunks = text_splitter.split_documents(extracted_data)
return text_chunks
text_chunks = text_split(extracted_data)
print("length of my chunk:", len(text_chunks))
#download embedding model
def download_hugging_face_embeddings():
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
return embeddings
embeddings = download_hugging_face_embeddings()
embeddings
query_result = embeddings.embed_query("Hello world")
print("Length", len(query_result))
import os
PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
pinecone_instance = Pinecone(PINECONE_API_KEY)
index = pinecone_instance.Index("chat")
index.upsert()
index_name = "chat"
docsearch=PV.from_texts([t.page_content for t in text_chunks], embeddings, index_name=index_name)