Spaces:
Running
Running
| from langchain_core.messages import HumanMessage, SystemMessage | |
| def expand_query(query,llm,factor=3): | |
| system_instruction= f""" | |
| You are an expert academic search optimization assistant for a college RAG database. | |
| Your job is to rewrite the user's input query into {factor} different, keyword-rich search variations. | |
| CRITICAL INSTRUCTIONS: | |
| 1. Maintain the exact semantic meaning but change casual or ambiguous phrasing into formal university terminology (e.g., convert 'faculties' to 'professors, lecturers, teaching staff', or 'syllabus' to 'curriculum scheme'). | |
| 2. Do NOT add any introductory text, pleasantries, or explanations. | |
| 3. Do NOT include numbers, bullet points, hyphens, or numbering prefixes (like '1.', '2.'). | |
| 4. Output ONLY the raw alternative queries, separating each distinct query with a single newline character (\n). | |
| """ | |
| messages= [SystemMessage(system_instruction),HumanMessage(query)] | |
| response= llm.invoke(messages) | |
| final_queries= response.content.split("\n\n") | |
| final_queries.append(query) | |
| return final_queries |