Code :
# import Libraries
import openai
import langchain
from langchain.document_loaders import PyPDFDirectoryLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Pinecone
from langchain_community.document_loaders import JSONLoader
from langchain.llms import OpenAI
import os
import tiktoken
# from pinecone import Pinecone, ServerlessSpec
loader = JSONLoader(
file_path='./flattened_data.json',
jq_schema='{text: .[].text,subtopic: .[].subtopic}',
text_content=False)
doc = loader.load()
def chunk_data(docs,chunk_size=800,chunk_overlap=50):
text_splitter=RecursiveCharacterTextSplitter(chunk_size=chunk_size,chunk_overlap=chunk_overlap)
doc=text_splitter.split_documents(docs)
return docs
documents=chunk_data(docs=doc)
len(documents)
OPENAI_API_KEY = ""
## Embedding Technique Of OPENAI
embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)
embeddings
vectors=embeddings.embed_query("How are you?")
len(vectors)
# from pinecone import Pinecone, ServerlessSpec
from pinecone import Pinecone
# Vector Search DB In Pinecone
pc = Pinecone(api_key="f64528b3-04f3-42bd-85ae-290f9ecda596")
index_name = "langchainvector"
index=Pinecone.from_documents(doc,embeddings,index_name=index_name)
Error :
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-15-4f0666e40ba9> in <cell line: 1>()
----> 1 index=Pinecone.from_documents(doc,embeddings,index_name=index_name)
AttributeError: type object 'Pinecone' has no attribute 'from_documents'