Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

surrealdb-python

БесплатноБез исполняемых скриптовНе проверен

Master SurrealDB 2.3.x with Python for multi-model database operations including CRUD, graph relationships, vector search, and real-time queries. Use when…

aiskillstoreот aiskillstore★ 509 звёзд на GitHub

Об этом скилле

SurrealDB Python

Overview

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.

When to Use This Skill

Apply this skill when:

  • Setting up SurrealDB connections and performing CRUD operations
  • Implementing graph databases with the RELATE statement and traversal queries
  • Building semantic search or RAG (Retrieval-Augmented Generation) applications with vector embeddings
  • Creating real-time applications with live queries
  • Designing multi-model schemas that combine documents, graphs, and vectors

Core Capabilities

1. Connection and Authentication

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

2. CRUD Operations

Perform standard database operations using intuitive Python methods:

  • create() - Insert new records with specific or auto-generated IDs
  • select() - Retrieve single records or entire tables
  • update() - Replace entire record contents
  • merge() - Partially update records by merging new fields
  • patch() - Apply JSON Patch operations for precise modifications
  • upsert() - Create if absent, update if present
  • delete() - Remove records or entire tables
  • query() - Execute raw SurrealQL for complex operations

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}
)

3. Graph Database Operations

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:

  • RELATE statement for creating edges between nodes
  • Arrow syntax (->, <->) for intuitive traversal
  • Recursive patterns with @.{depth} notation
  • Graph clauses for filtering during traversal
  • Edge tables that store relationship metadata

For comprehensive graph patterns, schema definitions, and best practices, see references/graph_operations.md.

4. Vector Search and Embeddings

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:

  • KNN operator <|k|> for k-nearest neighbor search
  • Multiple distance metrics (cosine, euclidean, manhattan)
  • Hybrid search combining vector and full-text search
  • Integration with popular embedding models (OpenAI, HuggingFace, Sentence Transformers)

For complete RAG implementations, embedding model comparisons, and optimization techniques, reference references/vector_search.md.

5. Real-Time Queries

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'
Полный SKILL.md на GitHub

Установить surrealdb-python в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/graph_operations.mdreferences/vector_search.mdskill-report.json

FAQ

Что делает скилл surrealdb-python?

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.

Как установить скилл surrealdb-python?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл surrealdb-python запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить surrealdb-python с