Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -105,17 +105,18 @@ async def chat(query,history,sources,reports,subtype,year):
|
|
105 |
|
106 |
##------------------------decide which collection to fetch------------------------------
|
107 |
if len(reports) == 0:
|
108 |
-
|
109 |
-
vectorstore = vectorstores[sources]
|
110 |
else:
|
111 |
-
print("selecting source:","allreports")
|
112 |
vectorstore = vectorstores["allreports"]
|
113 |
|
114 |
###-------------------------------------Construct Filter------------------------------------
|
115 |
if len(reports) == 0:
|
116 |
-
print("defining filter for
|
117 |
filter=rest.Filter(
|
118 |
-
must=[
|
|
|
|
|
|
|
119 |
rest.FieldCondition(
|
120 |
key="metadata.subtype",
|
121 |
match=rest.MatchValue(value=subtype)
|
@@ -123,9 +124,9 @@ async def chat(query,history,sources,reports,subtype,year):
|
|
123 |
rest.FieldCondition(
|
124 |
key="metadata.year",
|
125 |
match=rest.MatchAny(any=year)
|
126 |
-
)])
|
127 |
else:
|
128 |
-
print("defining filter for allreports")
|
129 |
filter=rest.Filter(
|
130 |
must=[
|
131 |
rest.FieldCondition(
|
@@ -139,7 +140,7 @@ async def chat(query,history,sources,reports,subtype,year):
|
|
139 |
question_lst= [query]
|
140 |
for question in question_lst:
|
141 |
retriever = vectorstore.as_retriever(
|
142 |
-
search_type="similarity_score_threshold", search_kwargs={"score_threshold": 0.6, "k":
|
143 |
|
144 |
context_retrieved = retriever.invoke(question)
|
145 |
print(len(context_retrieved))
|
|
|
105 |
|
106 |
##------------------------decide which collection to fetch------------------------------
|
107 |
if len(reports) == 0:
|
108 |
+
vectorstore = vectorstores["allreports"]
|
|
|
109 |
else:
|
|
|
110 |
vectorstore = vectorstores["allreports"]
|
111 |
|
112 |
###-------------------------------------Construct Filter------------------------------------
|
113 |
if len(reports) == 0:
|
114 |
+
print("defining filter for:",sources,":",subtype,":",year)
|
115 |
filter=rest.Filter(
|
116 |
+
must=[rest.FieldCondition(
|
117 |
+
key="metadata.source",
|
118 |
+
match=rest.MatchAny(value=sources)
|
119 |
+
),
|
120 |
rest.FieldCondition(
|
121 |
key="metadata.subtype",
|
122 |
match=rest.MatchValue(value=subtype)
|
|
|
124 |
rest.FieldCondition(
|
125 |
key="metadata.year",
|
126 |
match=rest.MatchAny(any=year)
|
127 |
+
),])
|
128 |
else:
|
129 |
+
print("defining filter for allreports:",reports)
|
130 |
filter=rest.Filter(
|
131 |
must=[
|
132 |
rest.FieldCondition(
|
|
|
140 |
question_lst= [query]
|
141 |
for question in question_lst:
|
142 |
retriever = vectorstore.as_retriever(
|
143 |
+
search_type="similarity_score_threshold", search_kwargs={"score_threshold": 0.6, "k": 5, "filter":filter})
|
144 |
|
145 |
context_retrieved = retriever.invoke(question)
|
146 |
print(len(context_retrieved))
|