Quick Start Guide

pip install cogdb
from cog.torque import Graph

# Create a graph and add data
g = Graph("social")
g.put("alice", "follows", "bob")
g.put("bob", "follows", "charlie")
g.put("bob", "status", "active")

# Query
g.v("alice").out("follows").all()                 # → {'result': [{'id': 'bob'}]}
g.v().has("status", "active").all()               # → {'result': [{'id': 'bob'}]}
g.v("alice").out("follows").out("follows").all()  # → {'result': [{'id': 'charlie'}]}

# Serve your graph over HTTP
g.serve()  # Now queryable at http://localhost:8080

# Expose to the internet
# g.server(share=True)
# print(g.share_url())  # https://abc123.s.cogdb.io

There is no server to start and no configuration files to manage. Data is stored locally and persists across restarts.

Data Model: Triples

CogDB stores data as triples. Each triple consists of a subject, a predicate, and an object.

subject → predicate → object

For example:

alice → follows → bob
bob → status → cool_person

Each triple represents a directed edge in the graph. Subjects and objects form the vertices, and predicates define the relationships between them.

Example

from cog.torque import Graph

g = Graph("people")

g.put("alice", "follows", "bob")
g.put("bob", "follows", "fred")
g.put("bob", "status", "cool_person")
g.put("charlie", "follows", "bob")
g.put("charlie", "follows", "dani")
g.put("dani", "follows", "bob")
g.put("dani", "follows", "greg")
g.put("dani", "status", "cool_person")
g.put("emily", "follows", "fred")
g.put("fred", "follows", "greg")
g.put("greg", "status", "cool_person")

Each call to put adds a single triple to the graph.

Querying the Graph

CogDB is queried using Torque, a graph raversal API.

Query example

Who do cool people follow?

g.v().has("status", "cool_person").out("follows").unique().all()
# {'result': [{'id': 'fred'}, {'id': 'bob'}, {'id': 'greg'}]}

Vector Search with Embeddings

CogDB supports storing vector embeddings on vertices and running similarity searches.

g.put_embedding("item1", [0.1, 0.2, 0.3])
g.v().k_nearest("item1", k=5).all()

Visualize a graph query result

g.v().tag("from").out("follows").tag("to").view("follows").url

Or use .render() in notebooks to render the graph inline.

On this page