semantica.embeddings converts text and graph structures into dense vector representations:
  • Provider-agnostic API: FastEmbed (default, ONNX, no GPU), Sentence-Transformers, OpenAI, BGE
  • Powers semantic search, entity resolution, GraphRAG retrieval, and deduplication
  • GraphEmbeddingManager embeds KG nodes and edges for graph database backends
  • Five pooling strategies: Mean (default), Max, CLS, Attention, Hierarchical
  • check_available_providers() shows which backends are installed in your environment

Why Embeddings Matter

Raw text can’t be compared mathematically. Embeddings translate meaning into geometry: two semantically similar sentences produce vectors that are close together in high-dimensional space, even when they share no words. Semantica uses embeddings for:
  • Semantic search: find knowledge graph nodes by meaning, not just keywords
  • Entity resolution: detect that “Apple Inc.” and “Apple Computer” refer to the same entity
  • Deduplication: semantic_v2 strategy measures entity similarity via embedding distance
  • GraphRAG retrieval: hybrid vector + graph traversal for grounded LLM answers
  • Semantic chunking: detect topic shift boundaries in TextSplitter(method="semantic_transformer")

Exported Classes

What You Get

  • EmbeddingGenerator — Main entry point: provider-agnostic, handles batching automatically across all backends.
  • TextEmbedder — Text-specific with automatic batching and progress tracking. Default method is FastEmbed.
  • GraphEmbeddingManager — Node and edge embeddings for graph databases: Neo4j, NetworkX, FalkorDB.
  • VectorEmbeddingManager — Prepare, normalize, and format embeddings for FAISS, Weaviate, Qdrant, and Milvus.
  • Provider StoresOpenAIStore, BGEStore, FastEmbedStore, and ProviderStoreFactory.
  • Pooling Strategies — Mean, Max, CLS, Attention, and Hierarchical: control token-to-vector aggregation.

Provider Setup

ONNX-accelerated local embeddings. No GPU required, no API key. Best starting point.
Default model is BAAI/bge-small-en-v1.5. Zero cost, zero GPU, works on any machine.
FastEmbed ignores the device parameter. FastEmbed uses ONNX Runtime and manages its own execution providers: passing device="cuda" has no effect. Switch to method="sentence_transformers" if you need explicit GPU control.
Check which providers are installed in your environment:

Getting Started

EmbeddingGenerator is the fastest path to embeddings: the default method is FastEmbed (ONNX, no GPU needed):
Always use the same model for indexing and querying. Vectors from different models are not comparable: they live in different vector spaces. Switching models requires re-embedding your entire corpus.
To switch provider after construction:

Quick Start

1

Install and initialize a provider

2

Generate embeddings

3

Compute similarity

4

Prepare for a vector database

Supported Models

EmbeddingGenerator

Best for: CPU-only production, lowest latency without GPU. Default: works out of the box.

Constructor Parameters

Use generator.set_text_model(method, model_name) to switch the embedding model after construction.

TextEmbedder

Direct text embedding with batch processing:

TextEmbedder Constructor Parameters

Key behaviours:
  • If FastEmbed or sentence-transformers is unavailable, falls back to a 128-dimensional hash-based embedding. Hash embeddings are deterministic but not semantic: do not use in production.
  • Large batches are chunked internally by the underlying library to avoid OOM.
Dimension mismatch. The dimension you pass to your vector store must exactly match your embedding model’s output. BAAI/bge-small-en-v1.5 → 384, all-MiniLM-L6-v2 → 384, all-mpnet-base-v2 → 768, BAAI/bge-large-en-v1.5 → 1024. Check with embedder.get_embedding_dimension() before creating the store.
Fallback embeddings are not semantic. If neither FastEmbed nor sentence-transformers loads successfully, TextEmbedder silently falls back to 128-dimensional SHA-256 hash embeddings. These are deterministic but carry no semantic meaning. Check embedder.get_method(): if it returns "fallback", install your intended provider.

Provider Stores

Use provider stores directly when you need fine-grained control over a single backend:
LlamaStore exists in the module but is a placeholder: it does not connect to Ollama and always raises ProcessingError at embed time. Do not use it in production.
LlamaStore is not functional. LlamaStore exists in the module but does not connect to Ollama. It always raises ProcessingError at embed time. Use FastEmbedStore for local ONNX-based embeddings or BGEStore for sentence-transformers-based local embeddings instead.

Pooling Strategies

Pooling aggregates a set of embeddings into a single vector: useful when you have multiple chunk embeddings to combine:
Best for: retrieval, semantic search, and clustering: averages all contributions.

GraphEmbeddingManager

Embed graph nodes and edges for storage in graph databases:
Supported backends: "neo4j", "networkx", "falkordb"

VectorEmbeddingManager

Prepare and validate embeddings for vector database storage:
Supported backends: "faiss", "weaviate", "qdrant", "milvus"

Common Workflows

Similarity Computation

Convenience Functions

  • Vector Store — Store and search the generated embeddings.
  • Split — Chunk text before embedding for better retrieval quality.
  • KG Module — Distance Intelligence uses graph embeddings for semantic neighbourhoods.
  • Deduplication — Semantic deduplication uses embedding distance for entity resolution.