feat: Added Neo4j Source and Tool (#189)

- configure neo4j source with url, username, password, database
- configure neo4j tools with cypher statement and paramters
- tests based on the postgres tests
- neo4j.yaml for integration tests
---------

Co-authored-by: duwenxin <duwenxin@google.com>
This commit is contained in:
Michael Hunger
2025-01-14 17:17:18 +01:00
committed by GitHub
parent cce93629a9
commit 8a1224b9e0
14 changed files with 726 additions and 0 deletions

View File

@@ -30,3 +30,4 @@ We currently support the following types of kinds of sources:
PostgreSQL instance.
* [postgres](./postgres.md) - Connect to any PostgreSQL compatible database.
* [spanner](./spanner.md) - Connect to a Spanner database.
* [neo4j](./neo4j.md) - Connect to a Neo4j instance.

40
docs/sources/neo4j.md Normal file
View File

@@ -0,0 +1,40 @@
# Neo4j Source
[Neo4j][neo4j-docs] is a powerful, open source graph database
system with over 15 years of active development that has earned it a strong
reputation for reliability, feature robustness, and performance.
[neo4j-docs]: https://neo4j.com/docs
## Requirements
### Database User
This source only uses standard authentication. You will need to [create a
Neo4j user][neo4j-users] to log in to the database with, or use the default `neo4j` user if available.
[neo4j-users]: https://neo4j.com/docs/operations-manual/current/authentication-authorization/manage-users/
## Example
```yaml
sources:
my-neo4j-source:
kind: "neo4j"
uri: "neo4j+s://xxxx.databases.neo4j.io:7687"
user: "neo4j"
password: "my-password"
database: "neo4j"
```
## Reference
| **field** | **type** | **required** | **description** |
|-----------|:--------:|:------------:|---------------------------------------------------------------------|
| kind | string | true | Must be "neo4j". |
| uri | string | true | Connect URI ("bolt://localhost", "neo4j+s://xxx.databases.neo4j.io") |
| user | string | true | Name of the Neo4j user to connect as (e.g. "neo4j"). |
| password | string | true | Password of the Neo4j user (e.g. "my-password"). |
| database | string | true | Name of the Neo4j database to connect to (e.g. "neo4j"). |

View File

@@ -50,6 +50,9 @@ We currently support the following types of kinds of tools:
PostgreSQL-compatible database.
* [spanner](./spanner.md) - Run a Spanner (either googlesql or postgresql)
statement againts Spanner database.
* [neo4j-cypher](./neo4j-cypher.md) - Run a Cypher statement against a
Neo4j database.
## Specifying Parameters

View File

@@ -0,0 +1,59 @@
# Neo4j Cypher Tool
A "neo4j-cypher" tool executes a pre-defined Cypher statement against a Neo4j database. It's compatible with any of the following sources:
- [neo4j](../sources/neo4j.md)
The specified Cypher statement is executed as a [parameterized statement][neo4j-parameters],
and specified parameters will be used according to their name: e.g. `$id`.
[neo4j-parameters]: https://neo4j.com/docs/cypher-manual/current/syntax/parameters/
## Example
```yaml
tools:
search_movies_by_actor:
kind: neo4j-cypher
source: my-neo4j-movies-instance
statement: |
MATCH (m:Movie)<-[:ACTED_IN]-(p:Person)
WHERE p.name = $name AND m.year > $year
RETURN m.title, m.year
LIMIT 10
description: |
Use this tool to get a list of movies for a specific actor and a given minium release year.
Takes an full actor name, e.g. "Tom Hanks" and a year e.g 1993 and returns a list of movie titles and release years.
Do NOT use this tool with a movie title. Do NOT guess an actor name, Do NOT guess a year.
A actor name is a fully qualified name with first and last name separated by a space.
For example, if given "Hanks, Tom" the actor name is "Tom Hanks".
If the tool returns more than one option choose the most recent movies.
Example:
{{
"name": "Meg Ryan",
"year": 1993
}}
Example:
{{
"name": "Clint Eastwood",
"year": 2000
}}
parameters:
- name: name
type: string
description: Full actor name, "firstname lastname"
- name: year
type: integer
description: 4 digit number starting in 1900 up to the current year
```
## Reference
| **field** | **type** | **required** | **description** |
|-------------|----------:|:------------:|----------------------------------------------------------------------------------------------------|
| kind | string | true | Must be "neo4j-cypher". |
| source | string | true | Name of the source the Cypher query should execute on. |
| description | string | true | Description of the tool |
| statement | string | true | Cypher statement to execute |
| parameters | parameter | true | List of [parameters](README.md#specifying-parameters) that will be used with the Cypher statement. |