Questions for GraphDB:
- Store unique nodes
- Simple query: What does Alice like?
- Store Atomese atoms
- Store binary values
GraphDB | Data Model |
---|---|
AtomSpace | Hypergraph |
Neo4j | Property |
Dgraph | RDF |
Atomspace is hypergraph GraphDB where edge (link in Atomspace) can join any number of edges (nodes). RDF - Resource Description Framework
Docs:
Neo4j allows storing different nodes with the same label:
CREATE (:SampleNode)
CREATE (:SampleNode)
MATCH (n:SampleNode) RETURN count(n) as count;
Result: 2
// Alice
CREATE (alice:Alice)-[:LIKES]->(:ice_cream)
CREATE (alice)-[:LIKES]->(:apple)
CREATE (alice)-[:DISLIKES]->(:pear)
// Bob
CREATE (bob:Bob)-[:LIKES]->(:apple)
MATCH (:Alice)-[:LIKES]->(what) RETURN what;
Sample: Alice likes ice-cream:
Atomese:
EvaluationLink
PredicateNode "likes"
ListLink
ConceptNode "Alice"
ConceptNode "ice-cream"
Property graph:
CREATE (el:EvaluationLink)-[:LINK {index: "0"}]->(:PredicateNode {name: "likes"})
CREATE (el)-[:LINK {index: "1"}]->(ll:ListLink)
CREATE (ll)-[:LINK {index: "0"}]->(:ConceptNode {name: "Alice"})
CREATE (ll)-[:LINK {index: "1"}]->(:ConceptNode {name: "ice-cream"})
Neo4j does not support binary data as values. It is recommended to story binary values in a separate storage.
Properties are key-value pairs. The keys are always strings. Valid property value types are
all the Java primitives (int, byte, float, etc), java.lang.Strings, the Spatial and Temporal types
and arrays of any of these.
Please note that Neo4j does NOT accept arbitrary objects as property values.
setProperty() takes a java.lang.Object only to avoid an explosion of overloaded setProperty() methods.
Worst Practices for BLOBs in Neo4j
Using BLOB data in Neo4j is one of the very few real anti-patterns for graph databases, in my opinion.
If you have to deal with BLOB data, choose an appropriate store for that use case and use Neo4j
to store the URL that points you to the binary data.
Docs:
{
set {
_:SampleNode <name> "Sample" .
}
}
{
set {
_:SampleNode <name> "Sample" .
}
}
{
unique_nodes(func: allofterms(name, "Sample")) {
name
}
}
Two nodes are stored
{
set {
_:icecream <name> "Ice-cream" .
_:apple <name> "Apple" .
_:pear <name> "Pear" .
_:alice <name> "Alice" .
_:bob <name> "Bob" .
_:alice <likes> _:icecream .
_:alice <likes> _:apple .
_:alice <dislikes> _:pear .
_:bob <likes> _:apple .
}
}
{
unique_nodes(func: eq(name, "Alice")) {
name
likes {
name
}
}
}
Result:
"data": {
"unique_nodes": [
{
"name": "Alice",
"likes": [
{
"name": "Ice-cream"
},
{
"name": "Apple"
}
]
}
]
}
Binary blobs aren’t supported right now (although I think it’s a good idea to in the future).
As a work around though, you could always do something like Base 64 encoding in a string.
There are some (arbitrary) hardcoded limits in badger for value sizes (2GB). These are in place for technical reasons
to aid recovery when the data directory in case the data directory becomes corrupted for some reason.
docker pull dgraph/dgraph
mkdir -p ~/dgraph
# Run dgraphzero
docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph dgraph/dgraph dgraph zero
# In another terminal, now run dgraph
docker exec -it dgraph dgraph alpha --lru_mb 2048 --zero localhost:5080
# And in another, run ratel (Dgraph UI)
docker exec -it dgraph dgraph-ratel