forked from brettin/ARC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdf_store_loader.py
More file actions
47 lines (28 loc) · 1.24 KB
/
pdf_store_loader.py
File metadata and controls
47 lines (28 loc) · 1.24 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from langchain.document_loaders import PyPDFLoader
from langchain.embeddings import HuggingFaceEmbeddings
from os import listdir
from os.path import isfile, join, dirname, realpath
print(dirname(realpath(__file__)))
from _util import _print
t = _print('Start')
mypath="pdfs"
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
print(f'file_count: {len(onlyfiles)}')
# This needs to run parallel
t = _print("Loading documents", t)
document_count = page_count = 0
pages = [] # one pdf has one or more pages
for pdf in onlyfiles:
if pdf.endswith(".pdf"):
loader = PyPDFLoader("pdfs/" + pdf)
document_count = document_count + 1
pages = loader.load_and_split()
page_count = page_count + len(pages)
print(f'document_count: {document_count}\tpage_count: {page_count}')
# Need to get the embeddings and embed these new pages
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
# Equivalent to SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
# Tokenize
# Then should investigate the best way to embed. How big of chunks.
# Then need to load into a vector store
t = _print("Done loading documents", t)