File size: 1,050 Bytes
e2979c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from dotenv import load_dotenv,find_dotenv
from transformers import pipeline
import os



load_dotenv(find_dotenv())


from langchain_community.document_loaders import PyPDFLoader, DirectoryLoader
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import FAISS
import faiss
from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings

directory_path = "data"  # Path to the directory containing your PDF files
loader = DirectoryLoader(directory_path, glob="./*.pdf", loader_cls=PyPDFLoader)
documents = loader.load()

text_splitter = RecursiveCharacterTextSplitter(chunk_size=1024, chunk_overlap=200)
texts = text_splitter.split_documents(documents)

# Create a SentenceTransformer object
embeddings = HuggingFaceEmbeddings(model_name="nomic-ai/nomic-embed-text-v1-ablated",model_kwargs={"trust_remote_code":True})


db = FAISS.from_documents(texts, embeddings)


db.save_local("gym_vector_db")