@falkordb/text-to-cypher 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@falkordb/text-to-cypher",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Node.js bindings for FalkorDB text-to-cypher library - Convert natural language to Cypher queries",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -67,11 +67,13 @@
67
67
  "files": [
68
68
  "index.js",
69
69
  "index.d.ts",
70
+ "*.node",
70
71
  "README.md",
71
72
  "LICENSE",
72
73
  "CHANGELOG.md",
73
74
  "INTEGRATION.md",
74
- "examples/"
75
+ "examples/",
76
+ "templates/"
75
77
  ],
76
78
  "packageManager": "npm@9.6.7",
77
79
  "optionalDependencies": {
@@ -0,0 +1,2 @@
1
+ Given that the data from this cypher query {{CYPHER_QUERY}} is {{CYPHER_RESULT}} answer this: {{USER_QUESTION}}
2
+ In your answer do not mention the given data or the cypher query nor the cypher result
@@ -0,0 +1,74 @@
1
+ Task: Generate OpenCypher statements to query a graph database based on natural language questions.
2
+
3
+ Core Requirements:
4
+ Use ONLY the entities, relationship types, and properties defined in the provided ontology
5
+ Generate syntactically valid OpenCypher statements
6
+ Return comprehensive results including all relevant entities, relationships, and their attributes
7
+ Maintain correct relationship direction: arrows point from source to target as defined in ontology
8
+
9
+ Query Construction Rules:
10
+ 1. Entity Matching: Use exact entity labels and property names from the ontology
11
+ 2. String Comparison: Use CONTAINS operator for partial string matches, = for exact matches
12
+ 3. Case Sensitivity: Properties are case-sensitive; use appropriate casing from ontology
13
+ 4. Name Normalization: All names (from user input and graph data) should be treated as lowercase when performing comparisons
14
+ 5. Selective Returns: ALWAYS prefer returning specific properties over full entities:
15
+ - Questions asking "which", "what", "show", "list" + property/name/identifier → RETURN only those fields
16
+ - Example: "which properties connect entities" → RETURN p.name (NOT RETURN p)
17
+ - Example: "what are the names" → RETURN e.name (NOT RETURN e)
18
+ - Only return full entities for exploratory "describe", "tell me about", or relationship visualization queries
19
+ 6. Multiple Entities: When questions involve multiple entity types, include all relevant connections
20
+ 7. Simple Queries: For declarative statements or single entity names, extract the relevant entity and return it with its direct relationships (1-hop only)
21
+
22
+ Relationship Handling:
23
+ Respect relationship direction as defined in ontology (source -> target)
24
+ Use appropriate relationship types exactly as specified
25
+ For bidirectional queries, specify direction explicitly or use undirected syntax when appropriate
26
+
27
+ Advanced Features Available:
28
+ Variable length paths: -[:TYPE*minHops..maxHops]->
29
+ Bidirectional traversal: -[:TYPE]- (undirected) or -[:TYPE]<- (reverse)
30
+ Optional matching: OPTIONAL MATCH for non-required relationships
31
+ Named paths: path = (start)-[:REL]->(end)
32
+ Shortest paths: allShortestPaths((start)-[:REL*]->(end))
33
+ Weighted paths: algo.SPpaths() for single-pair, algo.SSpaths() for single-source
34
+
35
+ Value Matching Best Practices:
36
+ When matching property values, prefer exact matches when examples are provided
37
+ Use the example values as a guide for formatting and case sensitivity
38
+ For string matching, default to case-insensitive comparisons using toLower()
39
+ Examples in the ontology show the actual data format - follow these patterns
40
+
41
+ Error Handling:
42
+ If the question cannot be answered with the provided ontology, return: "UNABLE_TO_GENERATE: [brief reason]"
43
+ If entities or relationships mentioned don't exist in ontology, return: "UNABLE_TO_GENERATE: Required entities/relationships not found in ontology"
44
+ If unsure about property names or values, refer to the examples provided in the ontology
45
+
46
+ Output Format:
47
+ Return ONLY the OpenCypher statement enclosed in triple backticks
48
+ No explanations, apologies, or additional text
49
+ Ensure query is syntactically correct before returning
50
+
51
+ Query Validation Checklist:
52
+ All entities exist in ontology ✓
53
+ All relationships exist and have correct direction ✓
54
+ All properties exist for their respective entities ✓
55
+ Syntax is valid OpenCypher ✓
56
+ Query returns comprehensive results ✓
57
+
58
+ Ontology:
59
+ {{ONTOLOGY}}
60
+
61
+ *Important* When a relationship in the ontology lists the same entity label for both source and target (e.g., Entity -> Entity), treat it as bidirectional. You may match it in either direction or use undirected syntax `()-[:RELATES_TO]-()` so both endpoints are considered.
62
+
63
+ Example:
64
+ Question: "Which managers own technology stocks?"
65
+ Expected Output: "MATCH (m:Manager)-[:OWNS]->(s:Stock)
66
+ WHERE toLower(s.sector) CONTAINS 'technology'
67
+ RETURN m, s"
68
+
69
+ Simple Entity Query Example:
70
+ Question: "Apple" or "Show me Apple"
71
+ Expected Output: "MATCH (c:Company)
72
+ WHERE toLower(c.name) = 'apple'
73
+ OPTIONAL MATCH (c)-[r]-(connected)
74
+ RETURN c, r, connected"
@@ -0,0 +1,17 @@
1
+ Generate an OpenCypher statement to answer the following question using the provided ontology.
2
+
3
+ Requirements:
4
+ Use only entities, relationships, and properties from the ontology
5
+ Maintain correct relationship directions (source -> target)
6
+ Return specific properties when question asks for names, identifiers, or lists (e.g., RETURN p.name not RETURN p)
7
+ Ensure syntactically valid OpenCypher
8
+
9
+ Question: {{QUESTION}}
10
+
11
+ Validation Steps:
12
+ 1. Identify required entities and relationships from the question
13
+ 2. Verify all components exist in the ontology
14
+ 3. Construct query with proper syntax and direction
15
+ 4. Ensure comprehensive result set
16
+
17
+ Generated OpenCypher:
Binary file
Binary file