Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
search pipeline updated
Browse files- RAG/rag_DocumentSearcher.py +39 -31
RAG/rag_DocumentSearcher.py
CHANGED
|
@@ -49,12 +49,6 @@ def query_(awsauth,inputs, session_id,search_types):
|
|
| 49 |
url = host+path
|
| 50 |
r = requests.get(url, auth=awsauth, json=query_mm, headers=headers)
|
| 51 |
response_mm = json.loads(r.text)
|
| 52 |
-
# response_mm = ospy_client.search(
|
| 53 |
-
# body = query_mm,
|
| 54 |
-
# index = st.session_state.input_index+"_mm"
|
| 55 |
-
# )
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
hits = response_mm['hits']['hits']
|
| 60 |
context = []
|
|
@@ -72,6 +66,24 @@ def query_(awsauth,inputs, session_id,search_types):
|
|
| 72 |
|
| 73 |
searches = ['Keyword','Vector','NeuralSparse']
|
| 74 |
equal_weight = (int(100/num_queries) )/100
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
if(num_queries>1):
|
| 76 |
for index,search in enumerate(search_types):
|
| 77 |
|
|
@@ -81,31 +93,25 @@ def query_(awsauth,inputs, session_id,search_types):
|
|
| 81 |
weight = 1-sum(weights)
|
| 82 |
|
| 83 |
weights.append(weight)
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
},
|
| 97 |
-
"combination": {
|
| 98 |
-
"technique": "arithmetic_mean",
|
| 99 |
-
"parameters": {
|
| 100 |
-
"weights": weights
|
| 101 |
}
|
| 102 |
}
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
r = requests.put(url, auth=awsauth, json=s_pipeline_payload, headers=headers)
|
| 109 |
|
| 110 |
SIZE = 5
|
| 111 |
|
|
@@ -183,8 +189,10 @@ def query_(awsauth,inputs, session_id,search_types):
|
|
| 183 |
# query_sparse = sparse_["inference_results"][0]["output"][0]["dataAsMap"]["response"][0]
|
| 184 |
|
| 185 |
hits = []
|
| 186 |
-
if(num_queries>1):
|
| 187 |
-
|
|
|
|
|
|
|
| 188 |
else:
|
| 189 |
path = st.session_state.input_index+"/_search"
|
| 190 |
url = host+path
|
|
|
|
| 49 |
url = host+path
|
| 50 |
r = requests.get(url, auth=awsauth, json=query_mm, headers=headers)
|
| 51 |
response_mm = json.loads(r.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
hits = response_mm['hits']['hits']
|
| 54 |
context = []
|
|
|
|
| 66 |
|
| 67 |
searches = ['Keyword','Vector','NeuralSparse']
|
| 68 |
equal_weight = (int(100/num_queries) )/100
|
| 69 |
+
s_pipeline_payload = {}
|
| 70 |
+
s_pipeline_path = "_search/pipeline/rag-search-pipeline"
|
| 71 |
+
if(st.session_state.input_is_rerank):
|
| 72 |
+
s_pipeline_payload["response_processors"] = [
|
| 73 |
+
{
|
| 74 |
+
"rerank": {
|
| 75 |
+
"ml_opensearch": {
|
| 76 |
+
"model_id": "eUoo-ZMBTp0efWqBQ-5g"
|
| 77 |
+
},
|
| 78 |
+
"context": {
|
| 79 |
+
"document_fields": [
|
| 80 |
+
"processed_element"
|
| 81 |
+
]
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
if(num_queries>1):
|
| 88 |
for index,search in enumerate(search_types):
|
| 89 |
|
|
|
|
| 93 |
weight = 1-sum(weights)
|
| 94 |
|
| 95 |
weights.append(weight)
|
| 96 |
+
s_pipeline_payload["phase_results_processors"] = [
|
| 97 |
+
{
|
| 98 |
+
"normalization-processor": {
|
| 99 |
+
"normalization": {
|
| 100 |
+
"technique": "min_max"
|
| 101 |
+
},
|
| 102 |
+
"combination": {
|
| 103 |
+
"technique": "arithmetic_mean",
|
| 104 |
+
"parameters": {
|
| 105 |
+
"weights": weights
|
| 106 |
+
}
|
| 107 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
}
|
| 109 |
}
|
| 110 |
+
]
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
|
|
|
| 115 |
|
| 116 |
SIZE = 5
|
| 117 |
|
|
|
|
| 189 |
# query_sparse = sparse_["inference_results"][0]["output"][0]["dataAsMap"]["response"][0]
|
| 190 |
|
| 191 |
hits = []
|
| 192 |
+
if(num_queries>1 or st.session_state.input_is_rerank):
|
| 193 |
+
s_pipeline_url = host + s_pipeline_path
|
| 194 |
+
r = requests.put(s_pipeline_url, auth=awsauth, json=s_pipeline_payload, headers=headers)
|
| 195 |
+
path = st.session_state.input_index+"/_search?search_pipeline=rag-search-pipeline"
|
| 196 |
else:
|
| 197 |
path = st.session_state.input_index+"/_search"
|
| 198 |
url = host+path
|