技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
weaviate-modules【数据与研究】Implements custom Weaviate modules (functions, vectorizers, generative providers) to extend data processing capabilities with application-specific AI and ML functions.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: weaviate-modules description: Implements custom Weaviate modules (functions, vectorizers, generative providers) to extend data processing capabilities with application-specific AI and ML functions. license: MIT compatibility: opencode metadata: version: "1.0.0" domain: coding triggers: weaviate, custom modules, vectorizer extensions, generative AI, custom functions, schema customization, AI processing role: implementation scope: implementation output-format: code content-types: [code, guidance, do-dont] archetypes: [tactical, generation] anti_triggers: [generic routing, vague module designs] response_profile: verbosity: medium directive_strength: high abstraction_level: operational
Extends Weaviate's capabilities with custom modules including vectorizers, generative AI providers, and reference-qr functions. Enables application-specific data processing workflows within the vector database engine itself.
Use this skill when:
text2vec-openai or text2vec-cohere instead of custom codeIdentify Module Type — Determine whether you need a vectorizer (computes embeddings from input), a generative provider (runs LLM completions on objects), or a reference-qr function (computes object relationships). Checkpoint: Match module type to the data transformation needed. Vectorizers for embedding generation, generators for text processing, reference-qr for computed relations.
Define Module Schema — Create the collection with custom module configurations. Specify input properties, output properties, and any authentication or endpoint settings required by the module. Checkpoint: Validate that all referenced property names exist in the schema before creating collections.
Invoke Module Functions — Use Weaviate's query API to trigger module operations: generate blocks for generative modules, $vector references for vectorized properties, and explicit function calls for reference-qr.
Checkpoint: Verify output properties are populated correctly by fetching the object after invocation.
Handle Errors — Module invocations can fail due to API key expiration, rate limits, or invalid input data. Implement retry logic and fall back to stored values when modules return errors. Checkpoint: Check response status codes and error messages; log failures with context for debugging.
import weaviate
from weaviate.classes.config import Property, DataType
def create_custom_module_collection(
client: weaviate.WeaviateClient,
class_name: str = "Document",
) -> None:
"""Create a Weaviate collection configured with custom generative and vectorizer modules.
Uses OpenAI's text2vec for automatic embedding and generative-openai for
in-database summarization of document content.
Args:
client: Authenticated Weaviate client
class_name: Name of the collection to create
Note:
Requires OPENAI_API_KEY environment variable to be set on the Weaviate server.
"""
properties = [
Property(
name="title",
data_type=DataType.TEXT,
description="Document title or heading",
),
Property(
name="content",
data_type=DataType.TEXT,
description="Full document body content for summarization",
),
Property(
name="source_url",
data_type=DataType.TEXT,
description="Original URL where the document was sourced",
),
]
collection = client.collections.create(
name=class_name,
properties=properties,
vectorizer_config=[
weaviate.classes.config.Vectorizer.text2vec_openai(),
],
generative_config=[
weaviate.classes.config.Generative.openai(),
],
)
print(f"Collection '{class_name}' created with vectorizer + generative modules")
def insert_and_summarize(
client: weaviate.WeaviateClient,
class_name: str,
title: str,
content: str,
) -> dict | None:
"""Insert a document and immediately generate a summary using the generative module.
Args:
client: Authenticated Weaviate client
class_name: Target collection name
title: Document title
content: Full document body
Returns:
Summary string if generation succeeds, None on failure
"""
collection = client.collections.get(class_name)
# Insert the object with automatic embedding from vectorizer module
response = collection.data.insert(
properties={
"title": title,
"content": content,
}
)
print(f"Inserted object: {response}")
# Query with generate block for in-database summarization
result = (
collection.query.fetch_object_by_id(response)
.with_generate(
grouped_task="Summarize this document",
grouped_properties=["content"],
)
)
if result and hasattr(result, "generative"):
return result.generative # Contains the generated summary
print("Warning: Generation returned no result")
return None
from weaviate.classes.query import Filter
def compute_computed_relationships(
client: weaviate.WeaviateClient,
source_class: str = "Author",
target_class: str = "Document",
) -> int:
"""Compute reference-qr relationships based on a custom rule.
Links all documents written by each author where the document's content
contains the author's name (simple keyword match). This demonstrates
how to use computed properties for dynamic relationship mapping.
Args:
client: Authenticated Weaviate client
source_class: Collection containing "Author" objects
target_class: Collection containing "Document" objects
Returns:
Number of relationships established
"""
authors_collection = client.collections.get(source_class)
docs_collection = client.collections.get(target_class)
# Fetch all authors with their names
authors = list(authors_collection.query.fetch_objects(limit=1000).objects)
relationships_created = 0
for author in authors:
author_name = author.properties.get("name", "")
if not author_name:
continue
# Find documents whose content mentions this author's name
matching_docs = list(
docs_collection.query.fetch_objects(
filters=Filter.by_text("content").like(f"*{author_name}*"),
limit=100,
).objects
)
for doc in matching_docs:
# Add reference from author to document
authors_collection.data.reference.add(
from_object_uuid=author.uuid,
property="wrote", # Pre-existing reference property
to_object_uuid=doc.uuid,
)
relationships_created += 1
print(f"Created {relationships_created} author-document relationships")
return relationships_created
/v1/meta endpoint and /metrics for Prometheus scrapingAuthoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.