| 61 | |
| 62 | |
| 63 | async def whoQueryRewrite(self): |
| 64 | ans_struc = { |
| 65 | "rewritten_queries": ["query1", "query2", "query3", "query4", "query5"], |
| 66 | "query_count": "Number of queries generated (1-5)" |
| 67 | } |
| 68 | |
| 69 | prompt = f""" |
| 70 | You are helping to rewrite a complex search query into simpler keyword queries for a very simple |
| 71 | vector embedding search, which can easily get distracted. |
| 72 | The search engine works best with short, focused queries containing important keywords. |
| 73 | |
| 74 | Take the following query and break it down into up to 5 simpler search queries. |
| 75 | Each query should: |
| 76 | - Contain no more than 3 words |
| 77 | - Focus on the most important keywords and concepts |
| 78 | - Be diverse to cover different aspects of the original query |
| 79 | - Use only essential nouns, adjectives, or product terms |
| 80 | - Avoid common words like "for", "the", "some", "are", "that", "would", "be" |
| 81 | |
| 82 | The original query is: {self.query}""" |
| 83 | response = await ask_llm(prompt, ans_struc, level="high", |
| 84 | query_params=self.http_handler.query_params, timeout=10) |
| 85 | |
| 86 | # Extract the rewritten queries from the response |
| 87 | rewritten_queries = response.get("rewritten_queries", []) |
| 88 | |
| 89 | valid_queries = [q for q in rewritten_queries if q and isinstance(q, str) and q.strip()] |
| 90 | valid_queries.append(self.query) |
| 91 | print(valid_queries) |
| 92 | return valid_queries |
| 93 | |
| 94 | async def whoRetrieveInt(self, query): |
| 95 | # Check cache first |