Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
change ksize in RAG
Browse files- RAG/rag_DocumentSearcher.py +45 -14
RAG/rag_DocumentSearcher.py
CHANGED
|
@@ -29,13 +29,29 @@ def query_(awsauth,inputs, session_id,search_types):
|
|
| 29 |
"processed_element_embedding_bedrock-multimodal","processed_element_embedding_sparse","image_encoding","processed_element_embedding"
|
| 30 |
]
|
| 31 |
},
|
| 32 |
-
"query":
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
"
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
path = st.session_state.input_index+"_mm/_search"
|
|
@@ -141,14 +157,29 @@ def query_(awsauth,inputs, session_id,search_types):
|
|
| 141 |
if('Vector Search' in search_types):
|
| 142 |
|
| 143 |
embedding = invoke_models.invoke_model(question)
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
hybrid_payload["query"]["hybrid"]["queries"].append(vector_payload)
|
| 154 |
|
|
|
|
| 29 |
"processed_element_embedding_bedrock-multimodal","processed_element_embedding_sparse","image_encoding","processed_element_embedding"
|
| 30 |
]
|
| 31 |
},
|
| 32 |
+
"query": { # exact knn search
|
| 33 |
+
"script_score": {
|
| 34 |
+
"query": {
|
| 35 |
+
"match_all": {}
|
| 36 |
+
},
|
| 37 |
+
"script": {
|
| 38 |
+
"source": "knn_score",
|
| 39 |
+
"lang": "knn",
|
| 40 |
+
"params": {
|
| 41 |
+
"field": "processed_element_embedding_bedrock-multimodal",
|
| 42 |
+
"query_value": embedding,
|
| 43 |
+
"space_type": "cosinesimil"
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
}
|
| 47 |
+
}
|
| 48 |
+
# { #approximate knn search
|
| 49 |
+
# "knn": {
|
| 50 |
+
# "processed_element_embedding_bedrock-multimodal": {
|
| 51 |
+
# "vector": embedding,
|
| 52 |
+
# "k": k}
|
| 53 |
+
# }
|
| 54 |
+
# }
|
| 55 |
}
|
| 56 |
|
| 57 |
path = st.session_state.input_index+"_mm/_search"
|
|
|
|
| 157 |
if('Vector Search' in search_types):
|
| 158 |
|
| 159 |
embedding = invoke_models.invoke_model(question)
|
| 160 |
+
vector_payload = { # exact knn search
|
| 161 |
+
"script_score": {
|
| 162 |
+
"query": {
|
| 163 |
+
"match_all": {}
|
| 164 |
+
},
|
| 165 |
+
"script": {
|
| 166 |
+
"source": "knn_score",
|
| 167 |
+
"lang": "knn",
|
| 168 |
+
"params": {
|
| 169 |
+
"field": "processed_element_embedding",
|
| 170 |
+
"query_value": embedding,
|
| 171 |
+
"space_type": "cosinesimil"
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
# vector_payload = { # aproximate knn search
|
| 177 |
+
# "knn": {
|
| 178 |
+
# "processed_element_embedding": {
|
| 179 |
+
# "vector": embedding,
|
| 180 |
+
# "k": 2}
|
| 181 |
+
# }
|
| 182 |
+
# }
|
| 183 |
|
| 184 |
hybrid_payload["query"]["hybrid"]["queries"].append(vector_payload)
|
| 185 |
|