Spaces:
Sleeping
Sleeping
Commit
·
5847e55
1
Parent(s):
c46d1ce
added test_rag
Browse files- test_rag.py +30 -0
test_rag.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from src.rag import FaissDB
|
2 |
+
import argparse
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import os
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
if __name__ == "__main__":
|
9 |
+
parser = argparse.ArgumentParser()
|
10 |
+
parser.add_argument("--path_to_index", type=str, required=True)
|
11 |
+
args = parser.parse_args()
|
12 |
+
path_to_index = args.path_to_index
|
13 |
+
|
14 |
+
try:
|
15 |
+
faiss_db = FaissDB(emb_model=os.getenv("OPENAI_EMBEDDINGS_MODEL"))
|
16 |
+
faiss_db.load_index(path_to_index)
|
17 |
+
except Exception as e:
|
18 |
+
print(f"Error loading index: {e}")
|
19 |
+
exit(1)
|
20 |
+
|
21 |
+
while True:
|
22 |
+
query = input("Enter query: ")
|
23 |
+
if query == "exit":
|
24 |
+
break
|
25 |
+
try:
|
26 |
+
documents = faiss_db.similarity_search(query)
|
27 |
+
print("\n\n".join(documents))
|
28 |
+
except Exception as e:
|
29 |
+
print(f"Error searching for documents: {e}")
|
30 |
+
continue
|