danicafisher commited on
Commit
2624a11
·
verified ·
1 Parent(s): 1855f0c

Create helper_functions.py

Browse files
Files changed (1) hide show
  1. helper_functions.py +25 -0
helper_functions.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.document_loaders import PyMuPDFLoader, TextLoader
2
+ from langchain_community.vectorstores import Qdrant
3
+
4
+ def process_file(file):
5
+ documents = []
6
+ if file.endswith(".pdf"):
7
+ loader = PyMuPDFLoader(file)
8
+ docs = loader.load()
9
+ documents.extend(docs)
10
+ else:
11
+ loader = TextLoader(file)
12
+ docs = loader.load()
13
+ documents.extend(docs)
14
+ return documents
15
+
16
+
17
+ def add_to_qdrant(documents, embeddings, qdrant_client, collection_name):
18
+
19
+ Qdrant.from_documents(
20
+ documents,
21
+ embeddings,
22
+ url=qdrant_client.url,
23
+ prefer_grpc=True,
24
+ collection_name=collection_name,
25
+ )