Update app/vectorstore.py
Browse files- app/vectorstore.py +6 -6
app/vectorstore.py
CHANGED
|
@@ -29,7 +29,7 @@ class vectorstore:
|
|
| 29 |
self.index_path = path
|
| 30 |
self.vectorstore = self.load_vectorstore(self.index_path)
|
| 31 |
|
| 32 |
-
def chunk_text(self,text, chunk_size=
|
| 33 |
"""
|
| 34 |
Split text into chunks of approximately 'chunk_size' words.
|
| 35 |
|
|
@@ -47,7 +47,7 @@ class vectorstore:
|
|
| 47 |
chunks.append(chunk)
|
| 48 |
return chunks
|
| 49 |
|
| 50 |
-
def create_vectorstore_from_pdf(self,pdf_path, chunk_size=
|
| 51 |
"""
|
| 52 |
Extract text from a PDF using pypdf, chunk the text, compute embeddings,
|
| 53 |
and create a FAISS index.
|
|
@@ -78,7 +78,7 @@ class vectorstore:
|
|
| 78 |
index_path = self.save_vectorstore_with_timestamp_and_without(vectorstore, embedder_model)
|
| 79 |
return index_path
|
| 80 |
|
| 81 |
-
def create_vectorstore_from_website(self, url, chunk_size=
|
| 82 |
"""
|
| 83 |
Fetch text from a website, chunk the text, compute embeddings,
|
| 84 |
and create a FAISS index.
|
|
@@ -109,7 +109,7 @@ class vectorstore:
|
|
| 109 |
index_path = self.save_vectorstore_with_timestamp_and_without(vectorstore, embedder_model)
|
| 110 |
return index_path
|
| 111 |
|
| 112 |
-
def add_to_vectorstore_web(self, url, index_file_path, chunk_size=
|
| 113 |
"""
|
| 114 |
Fetch text from a website, chunk the text, compute embeddings using the existing embedder,
|
| 115 |
and add them to the existing FAISS vectorstore.
|
|
@@ -141,7 +141,7 @@ class vectorstore:
|
|
| 141 |
return updated_index_path
|
| 142 |
|
| 143 |
|
| 144 |
-
def add_to_vectorstore_from_pdf(self, pdf_path, chunk_size=
|
| 145 |
"""
|
| 146 |
Extract text from a PDF using PyPDF2, chunk the text, compute embeddings using the existing embedder,
|
| 147 |
and add them to the existing FAISS vectorstore.
|
|
@@ -206,7 +206,7 @@ class vectorstore:
|
|
| 206 |
return vectorstore
|
| 207 |
|
| 208 |
|
| 209 |
-
def search_vectorstore(self, query, top_k=
|
| 210 |
# Search using LangChain's similarity_search
|
| 211 |
docs = self.vectorstore.similarity_search(query, k=top_k)
|
| 212 |
results = [doc.page_content for doc in docs]
|
|
|
|
| 29 |
self.index_path = path
|
| 30 |
self.vectorstore = self.load_vectorstore(self.index_path)
|
| 31 |
|
| 32 |
+
def chunk_text(self,text, chunk_size=700):
|
| 33 |
"""
|
| 34 |
Split text into chunks of approximately 'chunk_size' words.
|
| 35 |
|
|
|
|
| 47 |
chunks.append(chunk)
|
| 48 |
return chunks
|
| 49 |
|
| 50 |
+
def create_vectorstore_from_pdf(self,pdf_path, chunk_size=700, embedder_model="all-MiniLM-L6-v2"):
|
| 51 |
"""
|
| 52 |
Extract text from a PDF using pypdf, chunk the text, compute embeddings,
|
| 53 |
and create a FAISS index.
|
|
|
|
| 78 |
index_path = self.save_vectorstore_with_timestamp_and_without(vectorstore, embedder_model)
|
| 79 |
return index_path
|
| 80 |
|
| 81 |
+
def create_vectorstore_from_website(self, url, chunk_size=700, embedder_model="all-MiniLM-L6-v2"):
|
| 82 |
"""
|
| 83 |
Fetch text from a website, chunk the text, compute embeddings,
|
| 84 |
and create a FAISS index.
|
|
|
|
| 109 |
index_path = self.save_vectorstore_with_timestamp_and_without(vectorstore, embedder_model)
|
| 110 |
return index_path
|
| 111 |
|
| 112 |
+
def add_to_vectorstore_web(self, url, index_file_path, chunk_size=700):
|
| 113 |
"""
|
| 114 |
Fetch text from a website, chunk the text, compute embeddings using the existing embedder,
|
| 115 |
and add them to the existing FAISS vectorstore.
|
|
|
|
| 141 |
return updated_index_path
|
| 142 |
|
| 143 |
|
| 144 |
+
def add_to_vectorstore_from_pdf(self, pdf_path, chunk_size=700):
|
| 145 |
"""
|
| 146 |
Extract text from a PDF using PyPDF2, chunk the text, compute embeddings using the existing embedder,
|
| 147 |
and add them to the existing FAISS vectorstore.
|
|
|
|
| 206 |
return vectorstore
|
| 207 |
|
| 208 |
|
| 209 |
+
def search_vectorstore(self, query, top_k=5):
|
| 210 |
# Search using LangChain's similarity_search
|
| 211 |
docs = self.vectorstore.similarity_search(query, k=top_k)
|
| 212 |
results = [doc.page_content for doc in docs]
|