技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
embeddings【数据与研究】Add embeddings to Unstructured elements with provider-specific encoders, credential-safe configuration, and metadata-preserving enrichment checks. Use when an agent needs BaseEmbeddingEncoder, EmbeddingConfig, OpenAI, OctoAI, Mixedbread, VoyageAI, VertexAI, Bedrock, or HuggingFace embedding guidance after partitioning or chunking.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill after documents have already been partitioned or chunked into Unstructured Element objects and the task is to attach vector embeddings to those elements or embed a search query with the same provider.
partitioning to create elements from files, URLs, HTML, text, or streams.chunking before embedding when the vector store should index RAG-sized chunks rather than raw document elements.elements-and-metadata when inspecting serialized element JSON or preserving coordinate/table/source metadata.references/provider-reference.md and install only the provider SDKs needed for that route.EmbeddingConfig and EmbeddingEncoder, then call:
embed_documents(elements) to mutate and return the same element objects with element.embeddings populated.embed_query(query) to produce a single query vector for retrieval.unstructured.embed.interfaces.EmbeddingConfig is a Pydantic base class; concrete providers add credential, model, region, batching, or client options.unstructured.embed.interfaces.BaseEmbeddingEncoder defines embed_documents(elements), embed_query(query), num_of_dimensions, is_unit_vector, and initialize().str(element) before embedding, so empty text-like elements can create low-value vectors or provider errors.embed_documents() writes vectors to element.embeddings; it is not a separate enrichment record and generally mutates the input elements in place.embeddings field, but ordinary metadata fields should remain intact if the element objects are preserved.import os
from unstructured.embed.openai import OpenAIEmbeddingConfig, OpenAIEmbeddingEncoder
config = OpenAIEmbeddingConfig(
api_key=os.environ["OPENAI_API_KEY"],
model_name="text-embedding-3-small",
)
encoder = OpenAIEmbeddingEncoder(config=config)
embedded_elements = encoder.embed_documents(chunks)
query_vector = encoder.embed_query("invoice due date")
For provider-specific names, credentials, dependency extras, batching behavior, and model caveats, use references/provider-reference.md.
Element objects rather than converting them to plain strings and rebuilding them.ElementMetadata, logs, vector-store payloads, and serialized JSON fixtures.metadata.orig_elements only when retrieval or citation workflows need source traceability; otherwise omit it upstream with the chunking sub-skill to keep payloads smaller.Use the bundled checker to verify importability and environment-variable presence without contacting providers or printing secret values:
python sub-skills/embeddings/scripts/embedding_config_check.py --provider openai
python sub-skills/embeddings/scripts/embedding_config_check.py --all --json
The checker intentionally does not call get_client(), embed_query(), or embed_documents(), because those may create SDK clients, read credential material, write provider-specific credential files, or make network calls.
partition() kwargs belong to partitioning.orig_elements decisions belong to chunking.elements-and-metadata.len(elements) equals the number of returned vectors; providers use assertions for this in several implementations.element_id, table metadata, and source provenance survive after embedding.