Spaces:
Sleeping
Sleeping
Update kig_core/graph_operations.py
Browse files
kig_core/graph_operations.py
CHANGED
|
@@ -88,27 +88,27 @@ def generate_cypher_guided(question: str, plan_step: int) -> str:
|
|
| 88 |
return "" # Return empty query if concept is invalid
|
| 89 |
selected_concept = found_match
|
| 90 |
|
| 91 |
-
|
| 92 |
# Determine the target node type based on plan step (example logic)
|
| 93 |
# This mapping might need adjustment based on the actual plan structure
|
| 94 |
if plan_step <= 1: # Steps 0 and 1: Context gathering
|
| 95 |
target = "(ts:TechnicalSpecification)"
|
| 96 |
-
fields = "ts.title, ts.scope, ts.description"
|
| 97 |
elif plan_step == 2: # Step 2: Research papers?
|
| 98 |
target = "(rp:ResearchPaper)"
|
| 99 |
-
fields = "rp.title, rp.abstract"
|
| 100 |
else: # Later steps might involve KeyIssues themselves or other types
|
| 101 |
target = "(n)" # Generic fallback
|
| 102 |
-
fields = "n.title, n.description" # Assuming common fields
|
| 103 |
|
| 104 |
# Construct Cypher query
|
| 105 |
# Ensure selected_concept is properly escaped if needed, though parameters are safer
|
| 106 |
-
|
|
|
|
| 107 |
# We return the query and the parameters separately for safe execution
|
| 108 |
# However, the planner currently expects just the string. Let's construct it directly for now.
|
| 109 |
# Be cautious about injection if concept names can contain special chars. Binding is preferred.
|
| 110 |
escaped_concept = selected_concept.replace("'", "\\'") # Basic escaping
|
| 111 |
-
cypher = f"MATCH (c:Concept {{name: '{escaped_concept}'}})-[:RELATED_TO]-{target} RETURN {fields}"
|
| 112 |
|
| 113 |
logger.info(f"Generated guided Cypher: {cypher}")
|
| 114 |
return cypher
|
|
@@ -182,7 +182,7 @@ def evaluate_documents(
|
|
| 182 |
result = invoke_llm(binary_grader,{"question": query, "document": formatted_doc})
|
| 183 |
logger.debug(f"Binary grader result for doc '{doc.get('title', 'N/A')}': {result}")
|
| 184 |
if result and 'yes' in result.lower():
|
| 185 |
-
valid_docs_with_scores.append((doc, 1.0))
|
| 186 |
except Exception as e:
|
| 187 |
logger.warning(f"Binary grading failed for a document: {e}", exc_info=True)
|
| 188 |
|
|
|
|
| 88 |
return "" # Return empty query if concept is invalid
|
| 89 |
selected_concept = found_match
|
| 90 |
|
|
|
|
| 91 |
# Determine the target node type based on plan step (example logic)
|
| 92 |
# This mapping might need adjustment based on the actual plan structure
|
| 93 |
if plan_step <= 1: # Steps 0 and 1: Context gathering
|
| 94 |
target = "(ts:TechnicalSpecification)"
|
| 95 |
+
fields = "ts.title, ts.scope, ts.description, ts.summary"
|
| 96 |
elif plan_step == 2: # Step 2: Research papers?
|
| 97 |
target = "(rp:ResearchPaper)"
|
| 98 |
+
fields = "rp.title, rp.abstract, rp.summary"
|
| 99 |
else: # Later steps might involve KeyIssues themselves or other types
|
| 100 |
target = "(n)" # Generic fallback
|
| 101 |
+
fields = "n.title, n.description, n.summary" # Assuming common fields
|
| 102 |
|
| 103 |
# Construct Cypher query
|
| 104 |
# Ensure selected_concept is properly escaped if needed, though parameters are safer
|
| 105 |
+
|
| 106 |
+
cypher = f"MATCH (c:Concept {{name: $conceptName}})-[:RELATED_TO]-{target} OPTIONAL MATCH (s:Solution)-[:SOLUTION_OF]->{target} WHERE {target}:KeyIssue RETURN {fields},s.summary LIMIT 10"
|
| 107 |
# We return the query and the parameters separately for safe execution
|
| 108 |
# However, the planner currently expects just the string. Let's construct it directly for now.
|
| 109 |
# Be cautious about injection if concept names can contain special chars. Binding is preferred.
|
| 110 |
escaped_concept = selected_concept.replace("'", "\\'") # Basic escaping
|
| 111 |
+
cypher = f"MATCH (c:Concept {{name: '{escaped_concept}'}})-[:RELATED_TO]-{target} OPTIONAL MATCH (s:Solution)-[:SOLUTION_OF]->{target} WHERE {target}:KeyIssue RETURN {fields},s.summary LIMIT 10"
|
| 112 |
|
| 113 |
logger.info(f"Generated guided Cypher: {cypher}")
|
| 114 |
return cypher
|
|
|
|
| 182 |
result = invoke_llm(binary_grader,{"question": query, "document": formatted_doc})
|
| 183 |
logger.debug(f"Binary grader result for doc '{doc.get('title', 'N/A')}': {result}")
|
| 184 |
if result and 'yes' in result.lower():
|
| 185 |
+
valid_docs_with_scores.append((doc, 1.0))
|
| 186 |
except Exception as e:
|
| 187 |
logger.warning(f"Binary grading failed for a document: {e}", exc_info=True)
|
| 188 |
|