@@ -97,7 +97,7 @@ func (t *OpenAICypherTranslator) GetSchema(ctx context.Context, projectID string
9797
9898// getSystemPrompt returns the system prompt for Cypher translation
9999func (t * OpenAICypherTranslator ) getSystemPrompt () string {
100- return `You are a expert Neo4j Cypher query generator. ` +
100+ return `You are a expert Neo4j Cypher query generator for Go code analysis . ` +
101101 `Your task is to convert natural language questions into precise Cypher queries.
102102
103103IMPORTANT RULES:
@@ -108,12 +108,32 @@ IMPORTANT RULES:
1081085. Always include LIMIT clauses to prevent excessive results (default: 50)
1091096. Use parameterized queries when possible
1101107. Focus on performance and accuracy
111+ 8. Functions have a 'package' property - use it directly instead of traversing relationships
111112
112- COMMON PATTERNS:
113- - Find functions: MATCH (f:Function) WHERE f.name CONTAINS $name RETURN f
114- - Find dependencies: MATCH (f1:File)-[:DEPENDS_ON]->(f2:File) RETURN f1, f2
115- - Find callers: MATCH (f1:Function)-[:CALLS]->(f2:Function) WHERE f2.name = $name RETURN f1
116- - Find implementations: MATCH (s:Struct)-[:IMPLEMENTS]->(i:Interface) RETURN s, i
113+ WORKING QUERY EXAMPLES:
114+ Query: "Show me all handler functions in the mcp package"
115+ Cypher: MATCH (f:Function) WHERE f.package = 'mcp' AND toLower(f.name) CONTAINS 'handle' RETURN f LIMIT 50
116+
117+ Query: "Find functions that handle MCP requests"
118+ Cypher: MATCH (f:Function) WHERE toLower(f.name) CONTAINS 'mcp' RETURN f LIMIT 50
119+
120+ Query: "List all functions in package mcp"
121+ Cypher: MATCH (f:Function) WHERE f.package = 'mcp' RETURN f LIMIT 50
122+
123+ Query: "Show functions with names starting with handle"
124+ Cypher: MATCH (f:Function) WHERE f.name STARTS WITH 'handle' RETURN f LIMIT 50
125+
126+ Query: "Find all structs in the analyzer package"
127+ Cypher: MATCH (s:Struct) WHERE s.package = 'analyzer' RETURN s LIMIT 50
128+
129+ Query: "Show interfaces and their implementations"
130+ Cypher: MATCH (s:Struct)-[:IMPLEMENTS]->(i:Interface) RETURN s.name as struct, i.name as interface LIMIT 50
131+
132+ Query: "Find functions that call a specific function"
133+ Cypher: MATCH (f1:Function)-[:CALLS]->(f2:Function {name: 'Debug'}) RETURN f1.name, f1.package LIMIT 50
134+
135+ Query: "Show all packages and their file count"
136+ Cypher: MATCH (p:Package)-[:CONTAINS]->(f:File) RETURN p.name, count(f) as file_count ORDER BY file_count DESC
117137
118138Return only the Cypher query without any formatting or explanations.`
119139}
@@ -147,15 +167,21 @@ func (t *OpenAICypherTranslator) buildSchemaDescription(stats *graph.ProjectStat
147167 schema .WriteString ("- Constant: Constants with properties: name, type, value, is_exported\n " )
148168 schema .WriteString ("- Import: Import statements with properties: path, alias\n " )
149169 schema .WriteString ("\n RELATIONSHIP TYPES:\n " )
150- schema .WriteString ("- CONTAINS: Package->File, File->Function/Struct/Interface\n " )
151- schema .WriteString ("- IMPORTS: File->Package\n " )
152- schema .WriteString ("- CALLS: Function->Function\n " )
153- schema .WriteString ("- IMPLEMENTS: Struct->Interface\n " )
154- schema .WriteString ("- HAS_METHOD: Struct->Function\n " )
155- schema .WriteString ("- DEPENDS_ON: File->File\n " )
156- schema .WriteString ("- HAS_FIELD: Struct->Variable\n " )
170+ schema .WriteString ("- CONTAINS: Package->File (packages contain files)\n " )
171+ schema .WriteString ("- DEFINES: File->Function/Struct/Interface/Variable/Constant (files define code elements)\n " )
172+ schema .WriteString ("- IMPORTS: File->Import (files have imports)\n " )
173+ schema .WriteString ("- CALLS: Function->Function (function call relationships)\n " )
174+ schema .WriteString ("- IMPLEMENTS: Struct->Interface (struct implements interface)\n " )
175+ schema .WriteString ("- HAS_METHOD: Struct->Function (struct has methods)\n " )
176+ schema .WriteString ("- DEPENDS_ON: File->File (file dependencies)\n " )
177+ schema .WriteString ("- HAS_FIELD: Struct->Variable (struct has fields)\n " )
157178 schema .WriteString (fmt .Sprintf ("\n Database contains %d nodes total.\n " , stats .TotalNodes ))
158179 schema .WriteString (fmt .Sprintf ("Database contains %d relationships total.\n " , stats .TotalRelationships ))
180+ schema .WriteString ("\n IMPORTANT NOTES:\n " )
181+ schema .WriteString ("- Functions have a 'package' property that can be queried directly\n " )
182+ schema .WriteString ("- To find functions in a package, use: MATCH (f:Function) WHERE f.package = 'packagename'\n " )
183+ schema .WriteString ("- Files DEFINE code elements (not CONTAINS)\n " )
184+ schema .WriteString ("- All nodes have a 'project_id' property for filtering\n " )
159185 return schema .String ()
160186}
161187
0 commit comments