Spaces:
Running
Running
Update custom_utils.py
Browse files- custom_utils.py +17 -1
custom_utils.py
CHANGED
|
@@ -80,6 +80,10 @@ def rag_retrieval(openai_api_key, prompt, db, collection, stages=[], vector_inde
|
|
| 80 |
|
| 81 |
def rag_inference(openai_api_key, prompt, search_results):
|
| 82 |
openai.api_key = openai_api_key
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
content = f"Answer this user question: {prompt} with the following context:\n{search_results}"
|
| 85 |
|
|
@@ -110,7 +114,18 @@ def vector_search(openai_api_key, user_query, db, collection, additional_stages=
|
|
| 110 |
"queryVector": query_embedding,
|
| 111 |
"path": "description_embedding",
|
| 112 |
"numCandidates": 150,
|
| 113 |
-
"limit":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
"filter": {
|
| 115 |
"$and": [
|
| 116 |
{"accommodates": {"$eq": 2}},
|
|
@@ -119,6 +134,7 @@ def vector_search(openai_api_key, user_query, db, collection, additional_stages=
|
|
| 119 |
},
|
| 120 |
}
|
| 121 |
}
|
|
|
|
| 122 |
|
| 123 |
pipeline = [vector_search_stage] + additional_stages
|
| 124 |
|
|
|
|
| 80 |
|
| 81 |
def rag_inference(openai_api_key, prompt, search_results):
|
| 82 |
openai.api_key = openai_api_key
|
| 83 |
+
|
| 84 |
+
print("###")
|
| 85 |
+
print(search_results)
|
| 86 |
+
print("###")
|
| 87 |
|
| 88 |
content = f"Answer this user question: {prompt} with the following context:\n{search_results}"
|
| 89 |
|
|
|
|
| 114 |
"queryVector": query_embedding,
|
| 115 |
"path": "description_embedding",
|
| 116 |
"numCandidates": 150,
|
| 117 |
+
"limit": 3,
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
""" filter
|
| 122 |
+
vector_search_stage = {
|
| 123 |
+
"$vectorSearch": {
|
| 124 |
+
"index": vector_index,
|
| 125 |
+
"queryVector": query_embedding,
|
| 126 |
+
"path": "description_embedding",
|
| 127 |
+
"numCandidates": 150,
|
| 128 |
+
"limit": 3,
|
| 129 |
"filter": {
|
| 130 |
"$and": [
|
| 131 |
{"accommodates": {"$eq": 2}},
|
|
|
|
| 134 |
},
|
| 135 |
}
|
| 136 |
}
|
| 137 |
+
"""
|
| 138 |
|
| 139 |
pipeline = [vector_search_stage] + additional_stages
|
| 140 |
|