Skip to content

Commit 3ee10ec

Browse files
committed
removed limit from neo4j block
1 parent 901f62f commit 3ee10ec

6 files changed

Lines changed: 26 additions & 49 deletions

File tree

apps/docs/content/docs/en/tools/memory.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ Add a new memory to the database or append to existing memory with the same ID.
2626

2727
| Parameter | Type | Required | Description |
2828
| --------- | ---- | -------- | ----------- |
29-
| `conversationId` | string | Yes | Conversation identifier \(e.g., user-123, session-abc\). If a memory with this conversationId already exists for this block, the new message will be appended to it. |
29+
| `conversationId` | string | No | Conversation identifier \(e.g., user-123, session-abc\). If a memory with this conversationId already exists for this block, the new message will be appended to it. |
30+
| `id` | string | No | Legacy parameter for conversation identifier. Use conversationId instead. Provided for backwards compatibility. |
3031
| `role` | string | Yes | Role for agent memory \(user, assistant, or system\) |
3132
| `content` | string | Yes | Content for agent memory |
32-
| `blockId` | string | No | Optional block ID. If not provided, uses the current block ID from execution context. |
33+
| `blockId` | string | No | Optional block ID. If not provided, uses the current block ID from execution context, or defaults to "default". |
3334

3435
#### Output
3536

@@ -48,6 +49,7 @@ Retrieve memory by conversationId, blockId, blockName, or a combination. Returns
4849
| Parameter | Type | Required | Description |
4950
| --------- | ---- | -------- | ----------- |
5051
| `conversationId` | string | No | Conversation identifier \(e.g., user-123, session-abc\). If provided alone, returns all memories for this conversation across all blocks. |
52+
| `id` | string | No | Legacy parameter for conversation identifier. Use conversationId instead. Provided for backwards compatibility. |
5153
| `blockId` | string | No | Block identifier. If provided alone, returns all memories for this block across all conversations. If provided with conversationId, returns memories for that specific conversation in this block. |
5254
| `blockName` | string | No | Block name. Alternative to blockId. If provided alone, returns all memories for blocks with this name. If provided with conversationId, returns memories for that conversation in blocks with this name. |
5355

@@ -87,6 +89,7 @@ Delete memories by conversationId, blockId, blockName, or a combination. Support
8789
| Parameter | Type | Required | Description |
8890
| --------- | ---- | -------- | ----------- |
8991
| `conversationId` | string | No | Conversation identifier \(e.g., user-123, session-abc\). If provided alone, deletes all memories for this conversation across all blocks. |
92+
| `id` | string | No | Legacy parameter for conversation identifier. Use conversationId instead. Provided for backwards compatibility. |
9093
| `blockId` | string | No | Block identifier. If provided alone, deletes all memories for this block across all conversations. If provided with conversationId, deletes memories for that specific conversation in this block. |
9194
| `blockName` | string | No | Block name. Alternative to blockId. If provided alone, deletes all memories for blocks with this name. If provided with conversationId, deletes memories for that conversation in blocks with this name. |
9295

apps/docs/content/docs/en/tools/neo4j.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Integrate Neo4j graph database into the workflow. Can query, create, merge, upda
2020

2121
### `neo4j_query`
2222

23-
Execute MATCH queries to read nodes and relationships from Neo4j graph database
23+
Execute MATCH queries to read nodes and relationships from Neo4j graph database. For best performance and to prevent large result sets, include LIMIT in your query (e.g.,
2424

2525
#### Input
2626

@@ -33,8 +33,8 @@ Execute MATCH queries to read nodes and relationships from Neo4j graph database
3333
| `password` | string | Yes | Neo4j password |
3434
| `encryption` | string | No | Connection encryption mode \(enabled, disabled\) |
3535
| `cypherQuery` | string | Yes | Cypher query to execute \(typically MATCH statements\) |
36-
| `parameters` | object | No | Parameters for the Cypher query as a JSON object |
37-
| `limit` | number | No | Maximum number of records to return |
36+
| `parameters` | object | No | Parameters for the Cypher query as a JSON object. Use for any dynamic values including LIMIT \(e.g., query: "MATCH \(n\) RETURN n LIMIT $limit", parameters: \{limit: 100\}\). |
37+
| `parameters` | string | No | No description |
3838

3939
#### Output
4040

apps/sim/app/api/tools/neo4j/query/route.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ const QuerySchema = z.object({
1919
encryption: z.enum(['enabled', 'disabled']).default('disabled'),
2020
cypherQuery: z.string().min(1, 'Cypher query is required'),
2121
parameters: z.record(z.unknown()).nullable().optional().default({}),
22-
limit: z
23-
.union([z.coerce.number().int().positive(), z.literal(''), z.undefined()])
24-
.optional()
25-
.transform((val) => {
26-
if (val === '' || val === undefined || val === null) {
27-
return undefined
28-
}
29-
return val
30-
}),
3122
})
3223

3324
export async function POST(request: NextRequest) {
@@ -63,14 +54,7 @@ export async function POST(request: NextRequest) {
6354

6455
session = driver.session({ database: params.database })
6556

66-
let finalQuery = params.cypherQuery.trim()
67-
const finalParameters = { ...params.parameters }
68-
if (params.limit && !/\bLIMIT\s+\d+/i.test(finalQuery)) {
69-
finalQuery = `${finalQuery} LIMIT $limitValue`
70-
finalParameters.limitValue = params.limit
71-
}
72-
73-
const result = await session.run(finalQuery, finalParameters)
57+
const result = await session.run(params.cypherQuery, params.parameters)
7458

7559
const records = result.records.map((record) => {
7660
const obj: Record<string, unknown> = {}

apps/sim/blocks/blocks/neo4j.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,30 @@ Return ONLY the Cypher query. Do not include any explanations, markdown formatti
100100
2. **Filtering**: Use WHERE clauses for conditions
101101
3. **Return**: Specify what to return with RETURN
102102
4. **Performance**: Use indexes when possible
103-
5. **Limit Results**: Add LIMIT for large result sets
103+
5. **Limit Results**: ALWAYS include LIMIT to prevent large result sets
104+
105+
### IMPORTANT: LIMIT Best Practices
106+
- Always include LIMIT in your queries to prevent performance issues
107+
- Use parameterized LIMIT for flexibility: LIMIT $limit
108+
- Place LIMIT at the end after ORDER BY and SKIP clauses
109+
- Example: MATCH (n:Person) RETURN n ORDER BY n.name LIMIT $limit
104110
105111
### CYPHER QUERY PATTERNS
106112
107-
**Basic Node Match**:
113+
**Basic Node Match with LIMIT**:
108114
MATCH (n:Person) RETURN n LIMIT 25
109115
116+
**Match with Parameterized LIMIT (Recommended)**:
117+
MATCH (n:Person) RETURN n LIMIT $limit
118+
110119
**Match with Properties**:
111120
MATCH (n:Person {name: "Alice"}) RETURN n
112121
113122
**Match with Parameters (Recommended)**:
114-
MATCH (n:Person {name: $name}) RETURN n
123+
MATCH (n:Person {name: $name}) RETURN n LIMIT 100
115124
116125
**Match with WHERE and Parameters**:
117-
MATCH (n:Person) WHERE n.age > $minAge RETURN n.name, n.age
126+
MATCH (n:Person) WHERE n.age > $minAge RETURN n.name, n.age LIMIT $limit
118127
119128
**Match Relationship**:
120129
MATCH (p:Person)-[:KNOWS]->(friend:Person) RETURN p.name, friend.name
@@ -571,13 +580,6 @@ Return ONLY valid JSON.`,
571580
generationType: 'neo4j-parameters',
572581
},
573582
},
574-
{
575-
id: 'limit',
576-
title: 'Limit Results',
577-
type: 'short-input',
578-
placeholder: '100',
579-
condition: { field: 'operation', value: 'query' },
580-
},
581583
],
582584
tools: {
583585
access: [
@@ -653,11 +655,6 @@ Return ONLY valid JSON.`,
653655
result.parameters = undefined
654656
}
655657

656-
if (rest.limit && rest.limit !== '') {
657-
result.limit =
658-
typeof rest.limit === 'string' ? Number.parseInt(rest.limit, 10) : rest.limit
659-
}
660-
661658
if (rest.detach !== undefined) {
662659
result.detach = rest.detach === 'true' || rest.detach === true
663660
}
@@ -676,7 +673,6 @@ Return ONLY valid JSON.`,
676673
encryption: { type: 'string', description: 'Connection encryption mode' },
677674
cypherQuery: { type: 'string', description: 'Cypher query to execute' },
678675
parameters: { type: 'json', description: 'Query parameters as JSON object' },
679-
limit: { type: 'number', description: 'Limit number of records' },
680676
detach: { type: 'boolean', description: 'Use DETACH DELETE for delete operations' },
681677
},
682678
outputs: {

apps/sim/tools/neo4j/query.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type { ToolConfig } from '@/tools/types'
44
export const queryTool: ToolConfig<Neo4jQueryParams, Neo4jResponse> = {
55
id: 'neo4j_query',
66
name: 'Neo4j Query',
7-
description: 'Execute MATCH queries to read nodes and relationships from Neo4j graph database',
7+
description:
8+
'Execute MATCH queries to read nodes and relationships from Neo4j graph database. For best performance and to prevent large result sets, include LIMIT in your query (e.g., "MATCH (n:User) RETURN n LIMIT 100") or use LIMIT $limit with a limit parameter.',
89
version: '1.0',
910

1011
params: {
@@ -54,13 +55,8 @@ export const queryTool: ToolConfig<Neo4jQueryParams, Neo4jResponse> = {
5455
type: 'object',
5556
required: false,
5657
visibility: 'user-or-llm',
57-
description: 'Parameters for the Cypher query as a JSON object',
58-
},
59-
limit: {
60-
type: 'number',
61-
required: false,
62-
visibility: 'user-or-llm',
63-
description: 'Maximum number of records to return',
58+
description:
59+
'Parameters for the Cypher query as a JSON object. Use for any dynamic values including LIMIT (e.g., query: "MATCH (n) RETURN n LIMIT $limit", parameters: {limit: 100}).',
6460
},
6561
},
6662

@@ -79,7 +75,6 @@ export const queryTool: ToolConfig<Neo4jQueryParams, Neo4jResponse> = {
7975
encryption: params.encryption || 'disabled',
8076
cypherQuery: params.cypherQuery,
8177
parameters: params.parameters,
82-
limit: params.limit ? Number(params.limit) : undefined,
8378
}),
8479
},
8580

apps/sim/tools/neo4j/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export interface Neo4jConnectionConfig {
1212
export interface Neo4jQueryParams extends Neo4jConnectionConfig {
1313
cypherQuery: string
1414
parameters?: Record<string, unknown>
15-
limit?: number
1615
}
1716

1817
export interface Neo4jCreateParams extends Neo4jConnectionConfig {

0 commit comments

Comments
 (0)