Spaces:
Runtime error
Runtime error
Commit
•
5638045
1
Parent(s):
1174ad3
Undoing debug
Browse files- app.py +10 -11
- backend/semantic_search.py +30 -32
- requirements.txt +3 -1
app.py
CHANGED
@@ -31,17 +31,16 @@ def bot(history, system_prompt=""):
|
|
31 |
top_k = 5
|
32 |
query = history[-1][0]
|
33 |
|
34 |
-
|
35 |
-
#
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
#
|
42 |
-
|
43 |
-
|
44 |
-
prompt = query
|
45 |
logger.warning(prompt)
|
46 |
|
47 |
history[-1][1] = ""
|
|
|
31 |
top_k = 5
|
32 |
query = history[-1][0]
|
33 |
|
34 |
+
logger.warning('Retrieving documents...')
|
35 |
+
# Retrieve documents relevant to query
|
36 |
+
document_start = perf_counter()
|
37 |
+
documents = qd_retriever.retrieve(query, top_k=top_k)
|
38 |
+
document_time = document_start - perf_counter()
|
39 |
+
logger.warning(f'Finished Retrieving documents in {round(document_time, 2)} seconds...')
|
40 |
+
|
41 |
+
# Create Prompt
|
42 |
+
prompt = template.render(documents=documents, query=query)
|
43 |
+
prompt_html = template_html.render(documents=documents, query=query)
|
|
|
44 |
logger.warning(prompt)
|
45 |
|
46 |
history[-1][1] = ""
|
backend/semantic_search.py
CHANGED
@@ -1,33 +1,31 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
#
|
7 |
-
# # Setting up the logging
|
8 |
-
# logging.basicConfig(level=logging.INFO)
|
9 |
-
# logger = logging.getLogger(__name__)
|
10 |
-
#
|
11 |
-
# # Start the timer for loading the QdrantDocumentStore
|
12 |
-
# start_time = time.perf_counter()
|
13 |
-
#
|
14 |
-
# proj_dir = Path(__file__).parents[1]
|
15 |
-
# qd_document_store = QdrantDocumentStore(path=str(proj_dir/'Qdrant'), index='RAGDemo')
|
16 |
-
#
|
17 |
-
# # Log the time taken to load the QdrantDocumentStore
|
18 |
-
# document_store_loading_time = time.perf_counter() - start_time
|
19 |
-
# logger.info(f"Time taken to load QdrantDocumentStore: {document_store_loading_time:.6f} seconds")
|
20 |
-
#
|
21 |
-
# # Start the timer for loading the EmbeddingRetriever
|
22 |
-
# start_time = time.perf_counter()
|
23 |
-
#
|
24 |
-
# qd_retriever = EmbeddingRetriever(document_store=qd_document_store,
|
25 |
-
# embedding_model="BAAI/bge-base-en-v1.5",
|
26 |
-
# model_format="sentence_transformers",
|
27 |
-
# use_gpu=False)
|
28 |
-
#
|
29 |
-
# # Log the time taken to load the EmbeddingRetriever
|
30 |
-
# retriever_loading_time = time.perf_counter() - start_time
|
31 |
-
# logger.info(f"Time taken to load EmbeddingRetriever: {retriever_loading_time:.6f} seconds")
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import logging
|
3 |
+
from qdrant_haystack import QdrantDocumentStore
|
4 |
+
from haystack.nodes import EmbeddingRetriever
|
5 |
+
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Setting up the logging
|
8 |
+
logging.basicConfig(level=logging.INFO)
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
+
|
11 |
+
# Start the timer for loading the QdrantDocumentStore
|
12 |
+
start_time = time.perf_counter()
|
13 |
+
|
14 |
+
proj_dir = Path(__file__).parents[1]
|
15 |
+
qd_document_store = QdrantDocumentStore(path=str(proj_dir/'Qdrant'), index='RAGDemo')
|
16 |
+
|
17 |
+
# Log the time taken to load the QdrantDocumentStore
|
18 |
+
document_store_loading_time = time.perf_counter() - start_time
|
19 |
+
logger.info(f"Time taken to load QdrantDocumentStore: {document_store_loading_time:.6f} seconds")
|
20 |
+
|
21 |
+
# Start the timer for loading the EmbeddingRetriever
|
22 |
+
start_time = time.perf_counter()
|
23 |
+
|
24 |
+
qd_retriever = EmbeddingRetriever(document_store=qd_document_store,
|
25 |
+
embedding_model="BAAI/bge-base-en-v1.5",
|
26 |
+
model_format="sentence_transformers",
|
27 |
+
use_gpu=False)
|
28 |
+
|
29 |
+
# Log the time taken to load the EmbeddingRetriever
|
30 |
+
retriever_loading_time = time.perf_counter() - start_time
|
31 |
+
logger.info(f"Time taken to load EmbeddingRetriever: {retriever_loading_time:.6f} seconds")
|
requirements.txt
CHANGED
@@ -3,4 +3,6 @@ farm-haystack[inference]==1.20.1
|
|
3 |
qdrant-haystack==1.0.10
|
4 |
ipywidgets==8.1.1
|
5 |
tqdm==4.66.1
|
6 |
-
aiohttp==3.8.6
|
|
|
|
|
|
3 |
qdrant-haystack==1.0.10
|
4 |
ipywidgets==8.1.1
|
5 |
tqdm==4.66.1
|
6 |
+
aiohttp==3.8.6
|
7 |
+
huggingface-hub==0.17.3
|
8 |
+
transformers==4.34.1
|