Spaces:
Runtime error
Runtime error
Update core/vector_store.py
Browse files- core/vector_store.py +11 -5
core/vector_store.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 3 |
from langchain_community.vectorstores import Chroma
|
| 4 |
-
from
|
| 5 |
from chromadb.config import Settings
|
| 6 |
|
| 7 |
def create_or_load_vectorstore(text_chunks):
|
|
@@ -17,10 +17,11 @@ def create_or_load_vectorstore(text_chunks):
|
|
| 17 |
vectorstore = Chroma.from_documents(
|
| 18 |
documents=documents,
|
| 19 |
embedding=embeddings,
|
| 20 |
-
|
| 21 |
client_settings=Settings(
|
| 22 |
anonymized_telemetry=False,
|
| 23 |
-
is_persistent=False,
|
|
|
|
| 24 |
)
|
| 25 |
)
|
| 26 |
|
|
@@ -28,5 +29,10 @@ def create_or_load_vectorstore(text_chunks):
|
|
| 28 |
|
| 29 |
|
| 30 |
def similarity_search(vectorstore, query, k=5):
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 3 |
from langchain_community.vectorstores import Chroma
|
| 4 |
+
from langchain_core.documents import Document
|
| 5 |
from chromadb.config import Settings
|
| 6 |
|
| 7 |
def create_or_load_vectorstore(text_chunks):
|
|
|
|
| 17 |
vectorstore = Chroma.from_documents(
|
| 18 |
documents=documents,
|
| 19 |
embedding=embeddings,
|
| 20 |
+
collection_name=f"resume_{os.getpid()}_{id(documents)}",
|
| 21 |
client_settings=Settings(
|
| 22 |
anonymized_telemetry=False,
|
| 23 |
+
is_persistent=False,
|
| 24 |
+
chroma_db_impl="duckdb+parquet",
|
| 25 |
)
|
| 26 |
)
|
| 27 |
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
def similarity_search(vectorstore, query, k=5):
|
| 32 |
+
try:
|
| 33 |
+
documents = vectorstore.similarity_search(query, k=k)
|
| 34 |
+
return documents
|
| 35 |
+
except Exception as e:
|
| 36 |
+
print(f"Error in similarity search: {str(e)}")
|
| 37 |
+
|
| 38 |
+
return []
|