|
smollerGraph 0.20.2
A small graph database, from scratch
|
Accepted
Episode 1 needed a way to get its ten animals into the throwaway graph, without building them by hand in main. Every graph the series has used since came in the same way: the animals, a social graph generated for the benchmarks (episode 3), the mammals and birds on Wikidata (episode 10), and a model's predictions (episode 15).
(Red fox)-[:EATS]->(Rabbit), which episode 1 said "keeps the file easy to read, and close to how
we'd ask for them in Cypher". Blank lines and lines starting with # are skipped. From episode 9 a node can be a fact on its own, and nodes and relationships can have properties in braces, a string or a whole number; from episode 10 a node can have a label after a colon, as in (Rabbit:Animal {legs: 4}).LoadFacts reads a stream, not a file name, so a test can hand it a string. It stops at the first line it can't read, and returns that line as the error's message. A name is a node: adding a name the graph has gives back its node. A name, type, label, key or string too long for its record is refused before anything on its line is added.sg load adds a facts file to the graph in a folder (episode 2), and it's how a graph is written, with its embeddings written by sg embed (0020). Cypher, the page and the API read.tools/make_friends.cc, the generated social graph, with CSV files beside it for Neo4j and Kùzu (episode 3); tools/wikidata.py, data/wikidata.txt, 21,834 taxa from Wikidata's query service, whose data is under CC0, "so it's free to use, and to keep in our
repository" (episode 10); and tools/gnn.py, its predictions (episode 15).neo4j-admin's import, and into Kùzu, with COPY. make_friends writes those files for them, and they weren't weighed as smollerGraph's own way in.CREATE and SET, which write through the query language. This is the obvious alternative, and it wasn't weighed: properties come from facts, "as our Cypher can't set them
yet" (episode 9).AddNode and AddRelationship. In episode 3 it took 12.63 s for the generated million relationships, built without optimizations, against 0.63 s for Kùzu and 7.93 s for Neo4j, which read CSV files on several cores and write their files in large pieces. Optimized, it took 12.03 s, and the buffer pool took that to 1.07 s (episode 5, 0011).wikidata.py gives each taxon the first name that fits and isn't taken: its English name, its scientific name, or its Wikidata id (episode 10).wikidata.py puts a value with an apostrophe in double quotes (episode 10).sg load adds to a graph without touching anything else (episode 15).sg load and sg embed alone keeps the page safe to leave open on a server (0014). A graph that's written to needs to survive a crash part way through a write, which is what a write-ahead log is for, and the episodes up to 16 leave it for later.