Hi everyone! I’ve been running a RAG model on my local machine using Chroma and now trying to transition over to Pinecone. I’ve found some starter code floating where people are using Langchain’s “.from_texts” and “.from_documents” to create the vector DB from a given chunk of text.
However, I’m getting the attribute error: “type object ‘Pinecone’ has no attribute ‘from_documents’”. Did this function get depreciated somewhere and I’m just not seeing it? And if so, what is the alternative way to take a document, convert it into a vector format, and then insert it into a Pinecone instance? I have the following code below w/ the following imports
import os
import time
from dotenv import load_dotenv
from langchain_community.document_loaders import PyPDFLoader
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import OpenAIEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import Chroma, Pinecone
from langchain_core.runnables import RunnableParallel, RunnablePassthrough
from langchain.chains.question_answering import load_qa_chain
from langchain.chains import RetrievalQA, RetrievalQAWithSourcesChain
import chromadb
from pinecone import Pinecone, ServerlessSpec
pdf_folder_path = "./pdf_folder"
documents = []
for file in os.listdir(pdf_folder_path):
if file.endswith(".pdf"): #find all PDF's in pdf folder path
pdf_path = os.path.join(pdf_folder_path, file) #create the folder path as a prep for the PyPDF loader
print("loading PDF into loader...")
loader = PyPDFLoader(pdf_path)
documents.extend(loader.load()) #keep appending the load array
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=10)
chunked_documents = text_splitter.split_documents(documents) #create the individual pages
vector_db = Pinecone.from_documents(
documents = chunked_documents,
embedding = OpenAIEmbeddings(),
index_name = index
)