Spaces:
Running
Running
Update custom_utils.py
Browse files- custom_utils.py +16 -9
custom_utils.py
CHANGED
|
@@ -134,12 +134,16 @@ def vector_search_naive(openai_api_key,
|
|
| 134 |
"index": vector_index,
|
| 135 |
"queryVector": query_embedding,
|
| 136 |
"path": "description_embedding",
|
| 137 |
-
"numCandidates":
|
| 138 |
-
"limit":
|
| 139 |
}
|
| 140 |
}
|
| 141 |
|
| 142 |
-
pipeline = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
return invoke_search(db, collection, pipeline)
|
| 145 |
|
|
@@ -161,8 +165,8 @@ def vector_search_advanced(openai_api_key,
|
|
| 161 |
"index": vector_index,
|
| 162 |
"queryVector": query_embedding,
|
| 163 |
"path": "description_embedding",
|
| 164 |
-
"numCandidates":
|
| 165 |
-
"limit":
|
| 166 |
"filter": {
|
| 167 |
"$and": [
|
| 168 |
{"accommodates": {"$eq": accommodates}},
|
|
@@ -172,7 +176,10 @@ def vector_search_advanced(openai_api_key,
|
|
| 172 |
}
|
| 173 |
}
|
| 174 |
|
| 175 |
-
pipeline = [
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
return invoke_search(db, collection, pipeline)
|
| 178 |
|
|
@@ -258,11 +265,11 @@ def get_stage_include_fields():
|
|
| 258 |
}
|
| 259 |
}
|
| 260 |
|
| 261 |
-
def get_stage_filter_result():
|
| 262 |
return {
|
| 263 |
"$match": {
|
| 264 |
-
"accommodates": { "$eq":
|
| 265 |
-
"bedrooms": { "$eq":
|
| 266 |
}
|
| 267 |
}
|
| 268 |
|
|
|
|
| 134 |
"index": vector_index,
|
| 135 |
"queryVector": query_embedding,
|
| 136 |
"path": "description_embedding",
|
| 137 |
+
"numCandidates": 150,
|
| 138 |
+
"limit": 25,
|
| 139 |
}
|
| 140 |
}
|
| 141 |
|
| 142 |
+
pipeline = [
|
| 143 |
+
vector_search_stage,
|
| 144 |
+
get_stage_include_fields(),
|
| 145 |
+
get_stage_filter_result(accomodates, bedrooms)
|
| 146 |
+
]
|
| 147 |
|
| 148 |
return invoke_search(db, collection, pipeline)
|
| 149 |
|
|
|
|
| 165 |
"index": vector_index,
|
| 166 |
"queryVector": query_embedding,
|
| 167 |
"path": "description_embedding",
|
| 168 |
+
"numCandidates": 150,
|
| 169 |
+
"limit": 25,
|
| 170 |
"filter": {
|
| 171 |
"$and": [
|
| 172 |
{"accommodates": {"$eq": accommodates}},
|
|
|
|
| 176 |
}
|
| 177 |
}
|
| 178 |
|
| 179 |
+
pipeline = [
|
| 180 |
+
vector_search_and_filter_stage,
|
| 181 |
+
get_stage_include_fields()
|
| 182 |
+
] + additional_stages
|
| 183 |
|
| 184 |
return invoke_search(db, collection, pipeline)
|
| 185 |
|
|
|
|
| 265 |
}
|
| 266 |
}
|
| 267 |
|
| 268 |
+
def get_stage_filter_result(accomodates, bedrooms):
|
| 269 |
return {
|
| 270 |
"$match": {
|
| 271 |
+
"accommodates": { "$eq": accomodates},
|
| 272 |
+
"bedrooms": { "$eq": bedrooms}
|
| 273 |
}
|
| 274 |
}
|
| 275 |
|