Skip to content

Commit

Permalink
docs
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 20, 2024
1 parent 7f2e929 commit cefc9be
Show file tree
Hide file tree
Showing 16 changed files with 1,285 additions and 14 deletions.
102 changes: 102 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
**@accordproject/concerto-graph****Docs**

***

---
title: Concerto Graph
description: Store Concerto Concepts in a Graph DB
tags:
- Concerto
- Neo4J
- Graph
---

# Concerto Graph

This project uses a [Concerto model](https://concerto.accordproject.org) to define the nodes and edges in a Neo4J graph database and uses the model to validate the properties on the nodes.

![demo](demo.png)
[Demo](src/demo/index.ts)

In a few lines of code you can define a Concerto data model validated graph and perform a vector similarity search over
nodes with text content.

Concerto model (snippet):

```
concept Movie extends GraphNode {
@vector_index("summary", 1536, "COSINE")
o Double[] embedding optional
@embedding
o String summary optional
@label("IN_GENRE")
--> Genre[] genres optional
}
```

TypeScript code:

```typescript
await graphModel.mergeNode(transaction, `${NS}.Movie`, {identifier: 'Brazil', summary: 'The film centres on Sam Lowry, a low-ranking bureaucrat trying to find a woman who appears in his dreams while he is working in a mind-numbing job and living in a small apartment, set in a dystopian world in which there is an over-reliance on poorly maintained (and rather whimsical) machines'} );

await graphModel.mergeNode(transaction, `${NS}.Genre`, {identifier: 'Comedy'} );

await graphModel.mergeRelationship(transaction, `${NS}.Movie`, 'Brazil', `${NS}.Genre`, 'Comedy', 'genres' );

await graphModel.mergeNode(transaction, `${NS}.Director`, {identifier: 'Terry Gilliam'} );
await graphModel.mergeRelationship(transaction, `${NS}.Director`, 'Terry Gilliam', `${NS}.Movie`, 'Brazil', 'directed' );

await graphModel.mergeNode(transaction, `${NS}.Actor`, {identifier: 'Jonathan Pryce'} );
await graphModel.mergeRelationship(transaction, `${NS}.Actor`, 'Jonathan Pryce', `${NS}.Movie`, 'Brazil', 'actedIn' );

const search = 'Working in a boring job and looking for love.';
const results = await graphModel.similarityQuery(`${NS}.Movie`, 'embedding', search, 3);
```

Runtime result:

```json
[
{
identifier: 'Brazil',
content: 'The film centres on Sam Lowry, a low-ranking bureaucrat trying to find a woman who appears in his dreams while he is working in a mind-numbing job and living in a small apartment, set in a dystopian world in which there is an over-reliance on poorly maintained (and rather whimsical) machines',
score: 0.901830792427063
}
]
```

## Environment Variables

### GraphDB

- NEO4J_URL: the NEO4J URL. E.g. `neo4j+s://<DB_NAME>.databases.neo4j.io` if you are using AuraDB.
- NEO4J_PASS: your neo4j password.
- NEO4J_USER: <optional> defaults to `neo4j`

### Text Embeddings
- OPENAI_API_KEY: <optional> the OpenAI API key. If not set embeddings are not computed and written to the agreement graph and similarity search, natural language to Cypher generation ("chat with data") is not possible.

## API Index

### Classes

- [GraphModel](classes/GraphModel.md)

### Type Aliases

- [Context](type-aliases/Context.md)
- [GraphModelOptions](type-aliases/GraphModelOptions.md)
- [GraphNodeProperties](type-aliases/GraphNodeProperties.md)
- [SimilarityResult](type-aliases/SimilarityResult.md)

### Variables

- [ROOT\_MODEL](variables/ROOT_MODEL.md)
- [ROOT\_NAMESPACE](variables/ROOT_NAMESPACE.md)

### Functions

- [getObjectChecksum](functions/getObjectChecksum.md)
- [getOpenAiEmbedding](functions/getOpenAiEmbedding.md)
- [getTextChecksum](functions/getTextChecksum.md)
- [textToCypher](functions/textToCypher.md)
Loading

0 comments on commit cefc9be

Please sign in to comment.