Skip to content

Commit 2e882ec

Browse files
committed
docs
Signed-off-by: Dan Selman <[email protected]>
1 parent 536afb2 commit 2e882ec

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,55 @@ tags:
1111

1212
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.
1313

14+
![demo](demo.png)
15+
16+
In a few lines of code you can define a Concerto data model validated graph and perform a vector similarity search over
17+
nodes with text content.
18+
19+
Concerto model (snippet):
20+
21+
```
22+
concept Movie extends GraphNode {
23+
@vector_index("summary", 1536, "COSINE")
24+
o Double[] embedding optional
25+
@embedding
26+
o String summary optional
27+
@label("IN_GENRE")
28+
--> Genre[] genres optional
29+
}
30+
```
31+
32+
TypeScript code:
33+
34+
```typescript
35+
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'} );
36+
37+
await graphModel.mergeNode(transaction, `${NS}.Genre`, {identifier: 'Comedy'} );
38+
39+
await graphModel.mergeRelationship(transaction, `${NS}.Movie`, 'Brazil', `${NS}.Genre`, 'Comedy', 'genres' );
40+
41+
await graphModel.mergeNode(transaction, `${NS}.Director`, {identifier: 'Terry Gilliam'} );
42+
await graphModel.mergeRelationship(transaction, `${NS}.Director`, 'Terry Gilliam', `${NS}.Movie`, 'Brazil', 'directed' );
43+
44+
await graphModel.mergeNode(transaction, `${NS}.Actor`, {identifier: 'Jonathan Pryce'} );
45+
await graphModel.mergeRelationship(transaction, `${NS}.Actor`, 'Jonathan Pryce', `${NS}.Movie`, 'Brazil', 'actedIn' );
46+
47+
const search = 'Working in a boring job and looking for love.';
48+
const results = await graphModel.similarityQuery(`${NS}.Movie`, 'embedding', search, 3);
49+
```
50+
51+
Runtime result:
52+
53+
```json
54+
[
55+
{
56+
identifier: 'Brazil',
57+
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',
58+
score: 0.901830792427063
59+
}
60+
]
61+
```
62+
1463
## Environment Variables
1564

1665
### GraphDB
@@ -19,4 +68,4 @@ This project uses a [Concerto model](https://concerto.accordproject.org) to defi
1968
- NEO4J_PASS: <optional> the neo4j password.
2069

2170
### Text Embeddings
22-
- OPENAI_API_KEY: <optional> the OpenAI API key. If not set embeddings are not computed and written to the agreement graph.
71+
- OPENAI_API_KEY: <optional> the OpenAI API key. If not set embeddings are not computed and written to the agreement graph and similarity search is not possible.

demo.png

533 KB
Loading

0 commit comments

Comments
 (0)