Spaces:
Running
on
T4
Running
on
T4
model changed to Haiku 3.5 for query re=write
Browse files
semantic_search/query_rewrite.py
CHANGED
@@ -32,23 +32,6 @@ import utilities.invoke_models as invoke_models
|
|
32 |
|
33 |
|
34 |
|
35 |
-
bedrock_params = {
|
36 |
-
"max_tokens_to_sample":2048,
|
37 |
-
"temperature":0.0001,
|
38 |
-
"top_k":250,
|
39 |
-
"top_p":1,
|
40 |
-
"stop_sequences":["\\n\\nHuman:"]
|
41 |
-
}
|
42 |
-
bedrock_region="us-east-1"
|
43 |
-
|
44 |
-
#boto3_bedrock = boto3.client(service_name="bedrock-runtime", endpoint_url=f"https://bedrock-runtime.{bedrock_region}.amazonaws.com")
|
45 |
-
boto3_bedrock = boto3.client(service_name="bedrock-runtime", config=Config(region_name=bedrock_region))
|
46 |
-
|
47 |
-
bedrock_titan_llm = Bedrock(model_id="anthropic.claude-instant-v1", client=boto3_bedrock)
|
48 |
-
bedrock_titan_llm.model_kwargs = bedrock_params
|
49 |
-
bedrock_embeddings = BedrockEmbeddings(model_id='amazon.titan-embed-text-v1',client=boto3_bedrock)
|
50 |
-
|
51 |
-
|
52 |
schema = """{{
|
53 |
"content": "Brief summary of a retail product",
|
54 |
"attributes": {{
|
@@ -254,14 +237,9 @@ def get_new_query_res(query):
|
|
254 |
|
255 |
res = invoke_models.invoke_llm_model( prompt_.format(query=query,schema = schema) ,False)
|
256 |
inter_query = res[7:-3].replace('\\"',"'").replace("\n","")
|
257 |
-
print("inter_query")
|
258 |
-
print(inter_query)
|
259 |
query_struct = StructuredQueryOutputParser.from_components().parse(inter_query)
|
260 |
-
print("query_struct")
|
261 |
-
print(query_struct)
|
262 |
opts = OpenSearchTranslator()
|
263 |
result_query_llm = opts.visit_structured_query(query_struct)[1]['filter']
|
264 |
-
print(result_query_llm)
|
265 |
draft_new_query = {'bool':{'should':[],'must':[]}}
|
266 |
if('bool' in result_query_llm and ('must' in result_query_llm['bool'] or 'should' in result_query_llm['bool'])):
|
267 |
#draft_new_query['bool']['should'] = []
|
@@ -331,9 +309,7 @@ def get_new_query_res(query):
|
|
331 |
# return words_stem.strip()
|
332 |
|
333 |
#imp_item = stem_(imp_item)
|
334 |
-
|
335 |
-
print(imp_item)
|
336 |
-
print(query_)
|
337 |
if('must' in query_['bool']):
|
338 |
query_['bool']['must'].append({
|
339 |
"simple_query_string": {
|
|
|
32 |
|
33 |
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
schema = """{{
|
36 |
"content": "Brief summary of a retail product",
|
37 |
"attributes": {{
|
|
|
237 |
|
238 |
res = invoke_models.invoke_llm_model( prompt_.format(query=query,schema = schema) ,False)
|
239 |
inter_query = res[7:-3].replace('\\"',"'").replace("\n","")
|
|
|
|
|
240 |
query_struct = StructuredQueryOutputParser.from_components().parse(inter_query)
|
|
|
|
|
241 |
opts = OpenSearchTranslator()
|
242 |
result_query_llm = opts.visit_structured_query(query_struct)[1]['filter']
|
|
|
243 |
draft_new_query = {'bool':{'should':[],'must':[]}}
|
244 |
if('bool' in result_query_llm and ('must' in result_query_llm['bool'] or 'should' in result_query_llm['bool'])):
|
245 |
#draft_new_query['bool']['should'] = []
|
|
|
309 |
# return words_stem.strip()
|
310 |
|
311 |
#imp_item = stem_(imp_item)
|
312 |
+
|
|
|
|
|
313 |
if('must' in query_['bool']):
|
314 |
query_['bool']['must'].append({
|
315 |
"simple_query_string": {
|