Skip to content

Commit

Permalink
feat: deleteNode
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Selman <danscode@selman.org>
  • Loading branch information
dselman committed May 24, 2024
1 parent 479405a commit 8e78133
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 36 deletions.
4 changes: 2 additions & 2 deletions docs/classes/Conversation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Creates a new Conversation

#### Source

[Conversation.ts:22](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/Conversation.ts#L22)
[Conversation.ts:22](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/Conversation.ts#L22)

## Properties

Expand Down Expand Up @@ -63,4 +63,4 @@ the final result message

#### Source

[Conversation.ts:35](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/Conversation.ts#L35)
[Conversation.ts:35](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/Conversation.ts#L35)
64 changes: 45 additions & 19 deletions docs/classes/GraphModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Creates a new instance of GraphModel

#### Source

[graphmodel.ts:24](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L24)
[graphmodel.ts:24](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L24)

## Properties

Expand Down Expand Up @@ -65,7 +65,7 @@ the query results

#### Source

[graphmodel.ts:447](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L447)
[graphmodel.ts:459](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L459)

***

Expand All @@ -87,7 +87,7 @@ Closes a database context.

#### Source

[graphmodel.ts:67](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L67)
[graphmodel.ts:67](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L67)

***

Expand All @@ -103,7 +103,7 @@ Connects to Neo4J

#### Source

[graphmodel.ts:38](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L38)
[graphmodel.ts:38](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L38)

***

Expand All @@ -119,7 +119,7 @@ Create Neo4J constraints for the model

#### Source

[graphmodel.ts:192](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L192)
[graphmodel.ts:192](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L192)

***

Expand All @@ -135,7 +135,7 @@ Create fulltext indexes for the model

#### Source

[graphmodel.ts:232](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L232)
[graphmodel.ts:232](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L232)

***

Expand All @@ -152,7 +152,7 @@ for the model

#### Source

[graphmodel.ts:183](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L183)
[graphmodel.ts:183](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L183)

***

Expand All @@ -168,7 +168,7 @@ Create vector indexes for the model

#### Source

[graphmodel.ts:209](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L209)
[graphmodel.ts:209](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L209)

***

Expand All @@ -184,7 +184,33 @@ Delete all nodes/edges in the graph

#### Source

[graphmodel.ts:254](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L254)
[graphmodel.ts:254](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L254)

***

### deleteNode()

> **deleteNode**(`transaction`, `typeName`, `identifier`): `Promise`\<`QueryResult`\<`RecordShape`\>\>
Deletes a node and any relationships attached to the node (DETACH DELETE)

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `transaction` | `ManagedTransaction` | the transaction |
| `typeName` | `string` | the name of the type |
| `identifier` | `string` | the identifier for the node |

#### Returns

`Promise`\<`QueryResult`\<`RecordShape`\>\>

the result

#### Source

[graphmodel.ts:351](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L351)

***

Expand All @@ -200,7 +226,7 @@ Drop all Neo4J indexes for the model.

#### Source

[graphmodel.ts:154](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L154)
[graphmodel.ts:154](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L154)

***

Expand All @@ -226,7 +252,7 @@ the items

#### Source

[graphmodel.ts:479](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L479)
[graphmodel.ts:491](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L491)

***

Expand All @@ -244,7 +270,7 @@ an array of OpenAI tool definitions

#### Source

[graphmodel.ts:570](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L570)
[graphmodel.ts:582](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L582)

***

Expand Down Expand Up @@ -273,7 +299,7 @@ the graph node

#### Source

[graphmodel.ts:328](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L328)
[graphmodel.ts:328](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L328)

***

Expand Down Expand Up @@ -302,7 +328,7 @@ the source node

#### Source

[graphmodel.ts:354](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L354)
[graphmodel.ts:366](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L366)

***

Expand All @@ -327,7 +353,7 @@ a promise to a Context for the database.

#### Source

[graphmodel.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L55)
[graphmodel.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L55)

***

Expand All @@ -353,7 +379,7 @@ the query results

#### Source

[graphmodel.ts:301](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L301)
[graphmodel.ts:301](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L301)

***

Expand All @@ -380,7 +406,7 @@ an array of similar nodes, up to the count limit

#### Source

[graphmodel.ts:413](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L413)
[graphmodel.ts:425](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L425)

***

Expand All @@ -405,7 +431,7 @@ Performs a similarity search on nodes with text content

#### Source

[graphmodel.ts:270](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L270)
[graphmodel.ts:270](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L270)

***

Expand All @@ -429,4 +455,4 @@ the Cypher query

#### Source

[graphmodel.ts:436](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/graphmodel.ts#L436)
[graphmodel.ts:448](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/graphmodel.ts#L448)
2 changes: 1 addition & 1 deletion docs/functions/getOpenAiEmbedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ a promise to an array of numbers

## Source

[functions.ts:13](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/functions.ts#L13)
[functions.ts:12](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/functions.ts#L12)
2 changes: 1 addition & 1 deletion docs/type-aliases/Context.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Runtime context
## Source

[types.ts:30](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L30)
[types.ts:30](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L30)
2 changes: 1 addition & 1 deletion docs/type-aliases/EmbeddingCacheNode.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ A Node type that is used to cache vector embeddings
## Source

[types.ts:37](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L37)
[types.ts:37](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L37)
2 changes: 1 addition & 1 deletion docs/type-aliases/EmbeddingFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ vector embeddings for text

## Source

[types.ts:66](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L66)
[types.ts:66](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L66)
2 changes: 1 addition & 1 deletion docs/type-aliases/FullTextIndex.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Definition of a full text index over some properties
## Source

[types.ts:23](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L23)
[types.ts:23](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L23)
2 changes: 1 addition & 1 deletion docs/type-aliases/GraphModelOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Graph model options, used to configure Concerto Graph
## Source

[types.ts:78](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L78)
[types.ts:78](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L78)
2 changes: 1 addition & 1 deletion docs/type-aliases/GraphNodeProperties.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ The properties allowed on graph nodes

## Source

[types.ts:60](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L60)
[types.ts:60](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L60)
2 changes: 1 addition & 1 deletion docs/type-aliases/Logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Function signature for a logger

## Source

[types.ts:71](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L71)
[types.ts:71](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L71)
2 changes: 1 addition & 1 deletion docs/type-aliases/PropertyBag.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ A untyped set of properties

## Source

[types.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L55)
[types.ts:55](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L55)
2 changes: 1 addition & 1 deletion docs/type-aliases/SimilarityResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Result of a vector similarity search
## Source

[types.ts:46](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L46)
[types.ts:46](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L46)
2 changes: 1 addition & 1 deletion docs/type-aliases/ToolResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ The string that we should compute embedding vectors for

## Source

[types.ts:90](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L90)
[types.ts:90](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L90)
2 changes: 1 addition & 1 deletion docs/type-aliases/VectorIndex.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Definition of a vector (embeddings) index
## Source

[types.ts:14](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L14)
[types.ts:14](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L14)
2 changes: 1 addition & 1 deletion docs/variables/EMBEDDINGS_MAGIC.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ that include semantic embeddings

## Source

[types.ts:9](https://github.com/accordproject/lab-concerto-graph/blob/7f61653e6520d7e542d820dd570316a83b59870d/src/types.ts#L9)
[types.ts:9](https://github.com/accordproject/lab-concerto-graph/blob/479405ae077f731015a7cc00792f1e687d165a28/src/types.ts#L9)
3 changes: 3 additions & 0 deletions src/demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ async function run() {

await graphModel.mergeNode(transaction, 'Actor', { identifier: 'Johnny Depp' });
await graphModel.mergeRelationship(transaction, 'Actor', 'Johnny Depp', 'Movie', 'Fear and Loathing in Las Vegas', 'actedIn');

await graphModel.mergeNode(transaction, 'Person', { identifier: 'test' });
await graphModel.deleteNode(transaction, 'Person', 'test' );
});
{
const fullTextSearch = 'bats';
Expand Down
5 changes: 3 additions & 2 deletions src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as crypto from 'crypto'
import OpenAI from "openai";
import { EMBEDDINGS_MAGIC, GraphModelOptions, PropertyBag } from './types';
import { OPENAI_MODEL, OPENAI_TOOLS, getPrompt } from './prompt';
import { OPENAI_MODEL, OPENAI_TOOLS, TOOL_GET_EMBEDDINGS_NAME, getPrompt } from './prompt';

Check failure on line 4 in src/functions.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

'TOOL_GET_EMBEDDINGS_NAME' is defined but never used

/**
* Computes the vector embeddings for a text string.
Expand Down Expand Up @@ -33,7 +33,8 @@ export async function textToCypher(options: GraphModelOptions, text: string, cto
const runner = openai.beta.chat.completions
.runTools({
temperature: 0.05,
tool_choice: "auto",
tool_choice: 'auto',
// tool_choice: {type: 'function', function: {name: TOOL_GET_EMBEDDINGS_NAME}},
model: OPENAI_MODEL,
messages: [getPrompt(ctoModel, text)],
tools: OPENAI_TOOLS
Expand Down
12 changes: 12 additions & 0 deletions src/graphmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ export class GraphModel {
return this.query(`MERGE (n:${decl.getName()}{identifier: $id}) ${set}`, { id, ...newProperties }, transaction);
}

/**
* Deletes a node and any relationships attached to the node (DETACH DELETE)
* @param transaction the transaction
* @param typeName the name of the type
* @param identifier the identifier for the node
* @returns the result
*/
async deleteNode(transaction: ManagedTransaction, typeName: string, identifier: string) {
const decl = this.getGraphNodeDeclaration(typeName);
return this.query(`MATCH (n:${decl.getName()} {identifier: '${identifier}'}) DETACH DELETE n`, undefined, transaction);
}

/**
* Merges a relationship into the graph
* @param transaction the transaction
Expand Down

0 comments on commit 8e78133

Please sign in to comment.