skills/activeinferenceinstitute/surrealdb-python/SKILL.md
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.
npx skillsauth add aiskillstore/marketplace surrealdb-pythonInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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:
from 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:
# Create
user = await db.create("user", {
"name": "Alice",
"email": "[email protected]"
})
# 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:
# 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:
# 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:
from 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:
# 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:
# 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)
Define Schema:
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;
""")
Index Documents:
for doc in documents:
embedding = model.encode(doc["content"]).tolist()
await db.create("documents", {
"content": doc["content"],
"embedding": embedding,
"metadata": doc.get("metadata", {})
})
Semantic Search:
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})
Pass to LLM: Use retrieved context with language model for generation
Create Entities:
await db.create("concept:ai", {"name": "Artificial Intelligence"})
await db.create("concept:ml", {"name": "Machine Learning"})
Define Relationships:
await db.query("""
RELATE concept:ml->is_subset_of->concept:ai
SET confidence = 0.95
""")
Traverse and Query:
# 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:
# 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.
development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.