Files
semantica/cookbook/introduction/12_Embedding_Generation.ipynb
T
KaifAhmad1 7a6f1d0417 docs: add citation section and fix stale org references
Add a Cite Us section to the README with BibTeX citation info, and
align it with docs/citation.md (author/organization: Semantica, 2026).
Update LICENSE and docs/project-license.md copyright holder to
Semantica, and replace the stale Hawksight-AI GitHub org slug with
semantica-agi across READMEs, plugin manifests, cookbook notebooks,
and GitHub templates.
2026-08-24 16:07:22 +05:30

4.5 KiB

Open In Colab

Embedding Generation

Overview

This notebook demonstrates how to generate embeddings from text using Semantica's embedding modules. You'll learn to use EmbeddingGenerator and TextEmbedder to create vector representations of text.

Documentation: API Reference

Learning Objectives

  • Use EmbeddingGenerator to generate embeddings
  • Use TextEmbedder for text embedding generation
  • Generate embeddings for multiple texts
  • Understand embedding dimensions

Installation

Install Semantica from PyPI:

pip install semantica
# Or with all optional dependencies:
pip install semantica[all]

Step 1: Generate Embeddings

Generate embeddings using EmbeddingGenerator.

In [ ]:
!pip install semantica
In [ ]:
from semantica.embeddings import EmbeddingGenerator

generator = EmbeddingGenerator()

texts = [
    "Apple Inc. is a technology company.",
    "Microsoft Corporation develops software.",
    "Amazon provides cloud services."
]

embeddings = generator.generate_embeddings(texts, data_type="text")

print(f"Generated embeddings for {len(texts)} texts")
print(f"Embeddings shape: {embeddings.shape}")
print(f"First embedding dimension: {len(embeddings[0]) if len(embeddings) > 0 else 'N/A'}")

Step 2: Text Embedding

Use TextEmbedder for text-specific embeddings.

In [ ]:
from semantica.embeddings import TextEmbedder

text_embedder = TextEmbedder()

text = "Semantic knowledge graphs enable intelligent data processing."

embedding = text_embedder.embed_text(text)

print(f"Generated embedding for text")
print(f"First 5 values: {embedding[:5]}")

Step 3: Model Selection & Dynamic Switching

Semantica allows you to choose between different embedding providers (e.g., Sentence Transformers, FastEmbed) and switch models dynamically.

In [ ]:
# Initialize with a specific provider and model
embedder = TextEmbedder(method="sentence_transformers", model_name="all-MiniLM-L6-v2")
print(f"Current method: {embedder.get_method()}")

# Switch to FastEmbed dynamically
try:
    embedder.set_model(method="fastembed", model_name="BAAI/bge-small-en-v1.5")
    print(f"Switched to: {embedder.get_method()}")
    print(f"Model Info: {embedder.get_model_info()}")
except ImportError:
    print("FastEmbed not installed. Install with: pip install fastembed")

Summary

You've learned how to generate embeddings:

  • EmbeddingGenerator: Generate embeddings for multiple texts
  • TextEmbedder: Generate text-specific embeddings

Next: Learn how to store and search vectors in the Vector_Store notebook.