Spaces:
Sleeping
Sleeping
Update ragagent.py
Browse files- ragagent.py +8 -22
ragagent.py
CHANGED
@@ -99,29 +99,15 @@ class RAGAgent():
|
|
99 |
|
100 |
embedding_function = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
101 |
collection_name = re.sub(r'[^a-zA-Z0-9]', '', doc_splits[0].metadata.get('source'))
|
102 |
-
print(collection_name)
|
103 |
-
|
104 |
-
'''
|
105 |
-
client = chromadb.EphemeralClient()
|
106 |
-
|
107 |
-
try:
|
108 |
-
# If it exists, delete the existing collection
|
109 |
-
collection = client.get_collection(collection_name)
|
110 |
-
client.delete_collection(collection_name)
|
111 |
-
except:
|
112 |
-
pass
|
113 |
-
|
114 |
-
collection = client.create_collection(collection_name)
|
115 |
-
'''
|
116 |
|
117 |
persistent_client = chromadb.PersistentClient(settings=Settings(allow_reset=True))
|
118 |
-
persistent_client.reset()
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
|
123 |
collection = persistent_client.create_collection(collection_name)
|
124 |
-
print("
|
125 |
|
126 |
# Add to vectorDB
|
127 |
vectorstore = Chroma(
|
@@ -176,12 +162,12 @@ class RAGAgent():
|
|
176 |
web_search = "Yes"
|
177 |
|
178 |
for d in documents:
|
179 |
-
print("question: ",question)
|
180 |
-
print("document: ",d.page_content)
|
181 |
score = RAGAgent.retrieval_grader.invoke(
|
182 |
{"question": question, "document": d.page_content}
|
183 |
)
|
184 |
-
print("score: ",score)
|
185 |
grade = score["score"]
|
186 |
# Document relevant
|
187 |
if grade.lower() == "yes":
|
|
|
99 |
|
100 |
embedding_function = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
101 |
collection_name = re.sub(r'[^a-zA-Z0-9]', '', doc_splits[0].metadata.get('source'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
persistent_client = chromadb.PersistentClient(settings=Settings(allow_reset=True))
|
104 |
+
# persistent_client.reset()
|
105 |
+
if collection_name in [c.name for c in persistent_client.list_collections()]:
|
106 |
+
print("\ndeleted: ",collection_name)
|
107 |
+
persistent_client.delete_collection(collection_name)
|
108 |
|
109 |
collection = persistent_client.create_collection(collection_name)
|
110 |
+
print("\ncreated: ",collection_name)
|
111 |
|
112 |
# Add to vectorDB
|
113 |
vectorstore = Chroma(
|
|
|
162 |
web_search = "Yes"
|
163 |
|
164 |
for d in documents:
|
165 |
+
print("\n---- question: ",question)
|
166 |
+
print("\n---- document: ",d.page_content)
|
167 |
score = RAGAgent.retrieval_grader.invoke(
|
168 |
{"question": question, "document": d.page_content}
|
169 |
)
|
170 |
+
print("\n---- score: ",score)
|
171 |
grade = score["score"]
|
172 |
# Document relevant
|
173 |
if grade.lower() == "yes":
|