From 8e78133b0c3a8cb9cb393d291d79fc66c6e6c373 Mon Sep 17 00:00:00 2001 From: Dan Selman Date: Fri, 24 May 2024 10:27:32 +0100 Subject: [PATCH] feat: deleteNode Signed-off-by: Dan Selman --- docs/classes/Conversation.md | 4 +- docs/classes/GraphModel.md | 64 +++++++++++++++++------- docs/functions/getOpenAiEmbedding.md | 2 +- docs/type-aliases/Context.md | 2 +- docs/type-aliases/EmbeddingCacheNode.md | 2 +- docs/type-aliases/EmbeddingFunction.md | 2 +- docs/type-aliases/FullTextIndex.md | 2 +- docs/type-aliases/GraphModelOptions.md | 2 +- docs/type-aliases/GraphNodeProperties.md | 2 +- docs/type-aliases/Logger.md | 2 +- docs/type-aliases/PropertyBag.md | 2 +- docs/type-aliases/SimilarityResult.md | 2 +- docs/type-aliases/ToolResponse.md | 2 +- docs/type-aliases/VectorIndex.md | 2 +- docs/variables/EMBEDDINGS_MAGIC.md | 2 +- src/demo/index.ts | 3 ++ src/functions.ts | 5 +- src/graphmodel.ts | 12 +++++ 18 files changed, 78 insertions(+), 36 deletions(-) diff --git a/docs/classes/Conversation.md b/docs/classes/Conversation.md index 7844389..52d9589 100644 --- a/docs/classes/Conversation.md +++ b/docs/classes/Conversation.md @@ -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 @@ -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) diff --git a/docs/classes/GraphModel.md b/docs/classes/GraphModel.md index 187861c..717c17c 100644 --- a/docs/classes/GraphModel.md +++ b/docs/classes/GraphModel.md @@ -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 @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) *** @@ -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) diff --git a/docs/functions/getOpenAiEmbedding.md b/docs/functions/getOpenAiEmbedding.md index 06b47dd..9aa55c8 100644 --- a/docs/functions/getOpenAiEmbedding.md +++ b/docs/functions/getOpenAiEmbedding.md @@ -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) diff --git a/docs/type-aliases/Context.md b/docs/type-aliases/Context.md index 43b72ed..90a89c8 100644 --- a/docs/type-aliases/Context.md +++ b/docs/type-aliases/Context.md @@ -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) diff --git a/docs/type-aliases/EmbeddingCacheNode.md b/docs/type-aliases/EmbeddingCacheNode.md index d5c1c40..777d193 100644 --- a/docs/type-aliases/EmbeddingCacheNode.md +++ b/docs/type-aliases/EmbeddingCacheNode.md @@ -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) diff --git a/docs/type-aliases/EmbeddingFunction.md b/docs/type-aliases/EmbeddingFunction.md index 296c9ac..07632eb 100644 --- a/docs/type-aliases/EmbeddingFunction.md +++ b/docs/type-aliases/EmbeddingFunction.md @@ -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) diff --git a/docs/type-aliases/FullTextIndex.md b/docs/type-aliases/FullTextIndex.md index b0e9dce..9b25945 100644 --- a/docs/type-aliases/FullTextIndex.md +++ b/docs/type-aliases/FullTextIndex.md @@ -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) diff --git a/docs/type-aliases/GraphModelOptions.md b/docs/type-aliases/GraphModelOptions.md index 25220a1..79c7b51 100644 --- a/docs/type-aliases/GraphModelOptions.md +++ b/docs/type-aliases/GraphModelOptions.md @@ -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) diff --git a/docs/type-aliases/GraphNodeProperties.md b/docs/type-aliases/GraphNodeProperties.md index 4463ccb..4920450 100644 --- a/docs/type-aliases/GraphNodeProperties.md +++ b/docs/type-aliases/GraphNodeProperties.md @@ -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) diff --git a/docs/type-aliases/Logger.md b/docs/type-aliases/Logger.md index dbc42ab..3d74c25 100644 --- a/docs/type-aliases/Logger.md +++ b/docs/type-aliases/Logger.md @@ -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) diff --git a/docs/type-aliases/PropertyBag.md b/docs/type-aliases/PropertyBag.md index 432275a..47baed3 100644 --- a/docs/type-aliases/PropertyBag.md +++ b/docs/type-aliases/PropertyBag.md @@ -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) diff --git a/docs/type-aliases/SimilarityResult.md b/docs/type-aliases/SimilarityResult.md index 9ee6d24..c558e96 100644 --- a/docs/type-aliases/SimilarityResult.md +++ b/docs/type-aliases/SimilarityResult.md @@ -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) diff --git a/docs/type-aliases/ToolResponse.md b/docs/type-aliases/ToolResponse.md index 79f98ac..e49a8db 100644 --- a/docs/type-aliases/ToolResponse.md +++ b/docs/type-aliases/ToolResponse.md @@ -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) diff --git a/docs/type-aliases/VectorIndex.md b/docs/type-aliases/VectorIndex.md index 8daec4c..2cb0867 100644 --- a/docs/type-aliases/VectorIndex.md +++ b/docs/type-aliases/VectorIndex.md @@ -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) diff --git a/docs/variables/EMBEDDINGS_MAGIC.md b/docs/variables/EMBEDDINGS_MAGIC.md index 48379ee..28261d5 100644 --- a/docs/variables/EMBEDDINGS_MAGIC.md +++ b/docs/variables/EMBEDDINGS_MAGIC.md @@ -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) diff --git a/src/demo/index.ts b/src/demo/index.ts index 79fcc4f..5d03321 100644 --- a/src/demo/index.ts +++ b/src/demo/index.ts @@ -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'; diff --git a/src/functions.ts b/src/functions.ts index 00b5bd4..0acc4d1 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -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'; /** * Computes the vector embeddings for a text string. @@ -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 diff --git a/src/graphmodel.ts b/src/graphmodel.ts index 28c7ed3..eafbaf5 100644 --- a/src/graphmodel.ts +++ b/src/graphmodel.ts @@ -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