diff --git a/src/services/hybrid_rag_service.py b/src/services/hybrid_rag_service.py index aa2dbc8..3c3b9be 100644 --- a/src/services/hybrid_rag_service.py +++ b/src/services/hybrid_rag_service.py @@ -195,25 +195,21 @@ class HybridRAGService: Returns: Dictionary with keywords, entities, synonyms, expansions """ - prompt = f"""Extract search terms from this query. For each important word, provide synonyms and expansions. + prompt = f"""Extract search terms from this query. Query: "{query}" -Return ONLY valid JSON: -{{ - "core_keywords": ["key", "words", "from", "query"], - "synonyms": {{ - "word": ["alternative", "terms"] - }} -}} +RULES: +- Extract ONLY keywords explicitly present or directly implied in the query +- Do NOT invent terms, concepts, or synonyms not clearly related +- Do NOT add general knowledge or associations +- Provide synonyms ONLY for technical terms with well-known alternatives +- Return valid JSON only, no commentary -Example for "Docker container hosting": +Return format: {{ - "core_keywords": ["docker", "container", "hosting"], - "synonyms": {{ - "docker": ["containerization", "container runtime"], - "hosting": ["server", "infrastructure"] - }} + "core_keywords": ["words", "from", "query"], + "synonyms": {{"term": ["direct", "alternatives"]}} }} JSON:""" @@ -221,7 +217,8 @@ JSON:""" try: response = await self.ollama.generate_text( prompt=prompt, - model=self.reranker_model + model=self.reranker_model, + temperature=0.0 # Deterministic for consistent extraction ) # Parse JSON response (handle potential extra text) @@ -623,21 +620,27 @@ JSON:""" for i, r in enumerate(results) ]) - prompt = f"""Given this search query and documents, rank them by relevance. + prompt = f"""Rank these documents by relevance to the query. Query: {query} Documents: {docs_text} -Return only the numbers in order of relevance (most relevant first). -Example: 3,1,5,2,4 +RULES: +- Rank ONLY by how well content answers the query +- Do NOT consider document length, formatting, or style +- Do NOT add explanation or commentary +- Return ONLY comma-separated numbers, most relevant first + +Example output: 3,1,5,2,4 Ranking:""" response = await self.ollama.generate_text( prompt=prompt, - model=self.reranker_model + model=self.reranker_model, + temperature=0.0 # Deterministic for consistent rankings ) # Parse response: "3,1,5,2,4" → [2, 0, 4, 1, 3] (0-indexed)