Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Master SurrealDB 2.3.x with Python for multi-model database operations including CRUD, graph relationships, vector search, and real-time queries. Use when working with SurrealDB databases, implementing graph traversal, semantic search with embeddings, or building RAG applications.
.claude/skills/aiskillstore-surrealdb-python/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-15 | ✗→✓ | ▲ Improved | 33% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 126% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 34% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 67% | 0% |
| case-14 | ✗→✓ | ▲ Improved | 82% | 0% |
SurrealDB is a multi-model database that combines document, graph, and vector search capabilities in a single system. This skill provides comprehensive guidance for working with SurrealDB 2.3.x using the Python SDK, covering standard database operations, graph relationships, vector similarity search, and real-time data subscriptions.
Apply this skill when:
Establish connections to SurrealDB using the Python SDK with proper authentication:
pythonfrom surrealdb import AsyncSurreal async with AsyncSurreal("ws://localhost:8000/rpc") as db: await db.signin({"user": "root", "pass": "root"}) await db.use("namespace", "database") # Perform operations
Perform standard database operations using intuitive Python methods:
Example workflow:
python# Create user = await db.create("user", { "name": "Alice", "email": "alice@example.com" }) # Update specific fields await db.merge("user:alice", {"age": 30}) # Query with parameters results = await db.query( "SELECT * FROM user WHERE age > $min_age", {"min_age": 25} )
Leverage SurrealDB's native graph capabilities to model and traverse relationships without JOINs:
Creating Relationships:
python# Create entities await db.create("person:alice", {"name": "Alice"}) await db.create("person:bob", {"name": "Bob"}) # Create relationship with metadata await db.query(""" RELATE person:alice->knows->person:bob SET since = "2024-01-01", strength = "close" """)
Traversing Graphs:
python# Find friends of friends result = await db.query(""" SELECT ->knows->person->knows->person AS friends_of_friends FROM person:alice """) # Bidirectional traversal result = await db.query(""" SELECT <->connected_to<->city AS connected_cities FROM city:nyc """) # Recursive queries (variable depth) result = await db.query(""" SELECT @.{1,5}->manages->person AS management_chain FROM person:ceo """)
Key Graph Features:
->, <->) for intuitive traversal@.{depth} notationFor comprehensive graph patterns, schema definitions, and best practices, see references/graph_operations.md.
Implement semantic search and similarity-based retrieval using vector embeddings:
Storing Vectors:
pythonfrom sentence_transformers import SentenceTransformer model = SentenceTransformer("all-MiniLM-L6-v2") # Generate and store embedding text = "SurrealDB is a multi-model database" embedding = model.encode(text).tolist() await db.create("documents", { "content": text, "embedding": embedding, "metadata": {"source": "docs"} })
Semantic Search with KNN:
python# Generate query embedding query_text = "database features" query_embedding = model.encode(query_text).tolist() # Find 5 most similar documents result = await db.query(""" SELECT content, vector::similarity::cosine(embedding, $query_vector) AS similarity FROM documents WHERE embedding <|5|> $query_vector ORDER BY similarity DESC """, {"query_vector": query_embedding})
Key Vector Features:
<|k|> for k-nearest neighbor searchFor complete RAG implementations, embedding model comparisons, and optimization techniques, reference references/vector_search.md.
Subscribe to live data changes for real-time applications:
python# Start live query live_id = await db.live("user") # Subscribe to changes async for notification in db.subscribe_live(live_id): action = notification['action'] # 'CREATE', 'UPDATE', 'DELETE' data = notification['result'] print(f"Change detected: {action} - {data}") # Stop live query when done await db.kill(live_id)
python await db.query(""" DEFINE TABLE documents SCHEMAFULL; DEFINE FIELD content ON TABLE documents TYPE string; DEFINE FIELD embedding ON TABLE documents TYPE array; DEFINE FIELD metadata ON TABLE documents TYPE object; """)
python for doc in documents: embedding = model.encode(doc["content"]).tolist() await db.create("documents", { "content": doc["content"], "embedding": embedding, "metadata": doc.get("metadata", {}) })
python query_embedding = model.encode("user query").tolist() results = await db.query(""" SELECT content, metadata, vector::similarity::cosine(embedding, $query_vector) AS score FROM documents WHERE embedding <|5|> $query_vector ORDER BY score DESC """, {"query_vector": query_embedding})
python await db.create("concept:ai", {"name": "Artificial Intelligence"}) await db.create("concept:ml", {"name": "Machine Learning"})
python await db.query(""" RELATE concept:ml->is_subset_of->concept:ai SET confidence = 0.95 """)
python # Find all parent concepts recursively result = await db.query(""" SELECT @.{1,}->is_subset_of->concept AS parents FROM concept:ml """)
Leverage both graph relationships and semantic similarity:
python# Find semantically similar documents connected through graph relationships result = await db.query(""" SELECT *, vector::similarity::cosine(embedding, $query_vector) AS vec_score FROM documents WHERE embedding <|10|> $query_vector AND ->cited_by->document<-authored_by<-person = $author_id ORDER BY vec_score DESC """, { "query_vector": query_embedding, "author_id": "person:researcher1" })
async with) for automatic cleanupSurrealException for proper error handlingSCHEMAFULL for data integrityTIMEOUT 5s)FETCH to optimize queries that need related dataSemantic Search & RAG: Store document embeddings and perform similarity searches to retrieve relevant context for language models.
Knowledge Graphs: Model complex relationships between entities with typed edges and metadata, enabling sophisticated graph traversal queries.
Social Networks: Represent users and their connections, traverse friend relationships, and find mutual connections or recommendations.
Recommendation Systems: Combine collaborative filtering (graph relationships) with content-based filtering (vector similarity) for hybrid recommendations.
Real-Time Applications: Subscribe to data changes for live dashboards, chat applications, or notification systems.
This skill includes comprehensive reference documentation:
references/graph_operations.md - In-depth guide to graph database operations, RELATE syntax, traversal patterns, and schema designreferences/vector_search.md - Vector search implementation details, embedding model comparisons, RAG patterns, and LangChain integrationLoad these references when implementing specific features or troubleshooting issues.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-10 | pass→pass | 9,874 | 5,822 | -41% | 1 | 1 | 0% | 1,937 | 3,515 | +81% | 0 | 0 | — |
case-15 | fail→pass | 14,578 | 5,489 | -62% | 1 | 1 | 0% | 2,516 | 3,338 | +33% | 0 | 0 | — |
case-05 | pass→pass | 10,514 | 11,224 | +7% | 1 | 1 | 0% | 2,338 | 4,887 | +109% | 0 | 0 | — |
case-01 | fail→pass | 9,823 | 9,127 | -7% | 1 | 1 | 0% | 1,886 | 4,268 | +126% | 0 | 0 | — |
case-02 | fail→pass | 16,232 | 9,979 | -39% | 1 | 1 | 0% | 3,376 | 4,527 | +34% | 0 | 0 | — |
case-03 | fail→pass | 12,490 | 8,811 | -29% | 1 | 1 | 0% | 2,549 | 4,266 | +67% | 0 | 0 | — |
case-04 | pass→pass | 8,716 | 7,574 | -13% | 1 | 1 | 0% | 1,637 | 3,773 | +130% | 0 | 0 | — |
case-06 | pass→pass | 7,559 | 6,005 | -21% | 1 | 1 | 0% | 1,789 | 3,767 | +111% | 0 | 0 | — |
case-07 | pass→pass | 8,728 | 6,740 | -23% | 1 | 1 | 0% | 1,825 | 3,779 | +107% | 0 | 0 | — |
case-08 | pass→pass | 5,759 | 5,132 | -11% | 1 | 1 | 0% | 1,123 | 3,288 | +193% | 0 | 0 | — |
case-09 | pass→pass | 7,821 | 5,198 | -34% | 1 | 1 | 0% | 1,619 | 3,466 | +114% | 0 | 0 | — |
case-11 | pass→pass | 8,143 | 6,105 | -25% | 1 | 1 | 0% | 1,580 | 3,563 | +126% | 0 | 0 | — |
case-12 | pass→pass | 7,485 | 5,693 | -24% | 1 | 1 | 0% | 1,366 | 3,424 | +151% | 0 | 0 | — |
case-13 | pass→pass | 6,714 | 3,470 | -48% | 1 | 1 | 0% | 1,297 | 3,105 | +139% | 0 | 0 | — |
case-14 | fail→pass | 13,603 | 9,678 | -29% | 1 | 1 | 0% | 2,294 | 4,180 | +82% | 0 | 0 | — |
case-16 | pass→pass | 7,730 | 3,280 | -58% | 1 | 1 | 0% | 1,258 | 2,911 | +131% | 0 | 0 | — |
case-17 | fail→pass | 20,636 | 5,519 | -73% | 1 | 1 | 0% | 3,834 | 3,512 | -8% | 0 | 0 | — |
case-18 | pass→pass | 11,406 | 12,453 | +9% | 1 | 1 | 0% | 1,969 | 4,752 | +141% | 0 | 0 | — |
case-19 | fail→pass | 11,875 | 8,186 | -31% | 1 | 1 | 0% | 2,178 | 3,942 | +81% | 0 | 0 | — |
case-20 | pass→pass | 8,270 | 6,738 | -19% | 1 | 1 | 0% | 1,584 | 3,756 | +137% | 0 | 0 | — |
case-21 | pass→pass | 7,856 | 3,925 | -50% | 1 | 1 | 0% | 1,312 | 3,103 | +137% | 0 | 0 | — |
case-22 | pass→pass | 4,887 | 2,403 | -51% | 1 | 1 | 0% | 825 | 2,904 | +252% | 0 | 0 | — |
case-23 | pass→pass | 8,077 | 4,163 | -48% | 1 | 1 | 0% | 1,457 | 3,106 | +113% | 0 | 0 | — |
case-24 | pass→pass | 3,975 | 2,106 | -47% | 1 | 1 | 0% | 659 | 2,796 | +324% | 0 | 0 | — |
case-25 | pass→pass | 6,244 | 5,042 | -19% | 1 | 1 | 0% | 1,197 | 3,405 | +184% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 25 cases were attempted. The headline lift of +28 percentage points is the difference between those two pass rates over the 25 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.