Skip to main content

Quick Tutorial

This tutorial stores a small project graph, queries it, and searches it. Every step runs unchanged on RushDB Cloud and on a self-hosted engine; only the connection differs. You need a database from Get Started.

1. Install and connect​

pip install rushdb
import os
from rushdb import RushDB

if os.environ.get("RUSHDB_API_KEY"):
db = RushDB(os.environ["RUSHDB_API_KEY"]) # RushDB Cloud
else:
db = RushDB(os.environ["RUSHDB_TOKEN"], direct=True, engine_url="http://127.0.0.1:3000") # self-hosted

2. Push nested JSON​

Nested objects become their own records, linked to their parent. Keys in upper case become labels.

db.records.import_json(
{
"name": "Search revamp",
"status": "active",
"TASK": [
{"title": "Add keyword search to the docs site", "status": "done", "estimate": 3},
{"title": "Rank results by meaning and keywords", "status": "pending", "estimate": 5},
{"title": "Measure search latency", "status": "pending", "estimate": 2},
],
},
label="PROJECT",
)

3. Query across relationships​

Find the pending tasks of active projects, then total the remaining estimate. One SearchQuery shape filters, traverses and aggregates.

pending = db.records.find({
"labels": ["TASK"],
"where": {"status": "pending", "PROJECT": {"status": "active"}},
"orderBy": {"estimate": "desc"},
})
print(pending.total, [task.get("title") for task in pending.data])

remaining = db.records.find({
"labels": ["TASK"],
"where": {"status": "pending"},
"select": {"estimate": {"$sum": "$record.estimate"}},
})
print(remaining.data[0].get("estimate")) # 7

4. Search by keywords​

Declare a text index once; it is built in the background and kept current on every write.

db.text_indexes.create({"label": "TASK", "property": "title", "consistency": "immediate"})

hits = db.records.text_search({"labels": ["TASK"], "query": "search latency"})
for task in hits.data:
print(task.score, task.get("title"))

A search right after creating the index can report that the index is still building; wait until textIndexes.find() shows it ready.

5. Search by meaning​

Vector search ranks records by similarity of embeddings.

  • On RushDB Cloud, create a managed index and search with plain text; Cloud embeds both the records and the query:

    await db.ai.indexes.create({ label: 'TASK', propertyName: 'title' })
    // when the index status is 'ready':
    const similar = await db.records.vectorSearch({ labels: ['TASK'], propertyName: 'title', query: 'make search faster' })
  • On a self-hosted engine, the engine stores and searches vectors you produce: create an external index, write vectors from your model, and search with a queryVector. Follow Bring Your Own Vectors.

Add text: { query: 'latency' } to a vector search to make it hybrid: both rankings fused into one.

Next steps​

NextGuide
Model your own dataImport Data · Relationships
Learn the query languageSearchQuery · Where Operators
SearchKeyword · Semantic · Hybrid
Group writes atomicallyTransactions
Give an agent memoryAgent Memory Quickstart
Run the engine in productionEngine manual: Operations