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.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- embeddings
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- 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.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/provider-reference.md7.8 KB
- 参考文档references/troubleshooting.md6.2 KB
- 脚本scripts/embedding_config_check.py7.3 KB
03 SKILL.md 正文
Embeddings
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.
Start Here
- Route upstream work first:
- Use
partitioningto create elements from files, URLs, HTML, text, or streams. - Use
chunkingbefore embedding when the vector store should index RAG-sized chunks rather than raw document elements. - Use
elements-and-metadatawhen inspecting serialized element JSON or preserving coordinate/table/source metadata.
- Use
- Select the provider module from
references/provider-reference.mdand install only the provider SDKs needed for that route. - Read credentials from environment variables or a secret manager at runtime; never hard-code, log, serialize, or commit API keys.
- Instantiate the provider-specific
EmbeddingConfigandEmbeddingEncoder, then call:embed_documents(elements)to mutate and return the same element objects withelement.embeddingspopulated.embed_query(query)to produce a single query vector for retrieval.
- Validate vector count and dimensions before persistence, especially when mixing providers or overriding model dimensions.
Core Model
unstructured.embed.interfaces.EmbeddingConfigis a Pydantic base class; concrete providers add credential, model, region, batching, or client options.unstructured.embed.interfaces.BaseEmbeddingEncoderdefinesembed_documents(elements),embed_query(query),num_of_dimensions,is_unit_vector, andinitialize().- Provider implementations convert each element to text with
str(element)before embedding, so empty text-like elements can create low-value vectors or provider errors. embed_documents()writes vectors toelement.embeddings; it is not a separate enrichment record and generally mutates the input elements in place.- Serialized text elements may include an
embeddingsfield, but ordinary metadata fields should remain intact if the element objects are preserved.
Safe Pattern
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.
Metadata and Provenance
- Preserve source metadata by embedding existing
Elementobjects rather than converting them to plain strings and rebuilding them. - If downstream systems require enrichment provenance, add non-secret metadata outside the embedding vector itself, for example provider name, model name, and embedding timestamp managed by your application.
- Keep credentials and raw provider responses out of
ElementMetadata, logs, vector-store payloads, and serialized JSON fixtures. - If embedding chunks, preserve
metadata.orig_elementsonly when retrieval or citation workflows need source traceability; otherwise omit it upstream with thechunkingsub-skill to keep payloads smaller.
Bundled Helpers
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.
Routing Boundaries
- Raw document partitioning, OCR, table extraction, and
partition()kwargs belong topartitioning. - Chunk sizing, overlap, table chunking, and
orig_elementsdecisions belong tochunking. - Element JSON conversion, schema inspection, coordinates, and staging conversions belong to
elements-and-metadata. - Broad ingest connectors and destination vector-store writes are excluded; the in-repo embed package README notes this area moved toward Unstructured Ingest.
Review Checklist
- Confirm the provider SDK and optional dependencies are installed before suggesting runtime embedding.
- Confirm credentials are sourced securely and never shown in code examples, logs, or serialized elements.
- Confirm
len(elements)equals the number of returned vectors; providers use assertions for this in several implementations. - Confirm element text is non-empty and appropriate for the provider token/model limits.
- Confirm metadata,
element_id, table metadata, and source provenance survive after embedding. - Confirm query vectors use the same provider/model/dimension as indexed document vectors.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).