mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
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.
157 lines
4.5 KiB
Plaintext
157 lines
4.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"[](https://colab.research.google.com/github/semantica-agi/semantica/blob/main/cookbook/introduction/13_Embedding_Generation.ipynb)\n",
|
|
"\n",
|
|
"# Embedding Generation\n",
|
|
"\n",
|
|
"## Overview\n",
|
|
"\n",
|
|
"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.\n",
|
|
"\n",
|
|
"\n",
|
|
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/embeddings/)\n",
|
|
"\n",
|
|
"### Learning Objectives\n",
|
|
"\n",
|
|
"- Use `EmbeddingGenerator` to generate embeddings\n",
|
|
"- Use `TextEmbedder` for text embedding generation\n",
|
|
"- Generate embeddings for multiple texts\n",
|
|
"- Understand embedding dimensions\n",
|
|
"\n",
|
|
"## Installation\n",
|
|
"\n",
|
|
"Install Semantica from PyPI:\n",
|
|
"\n",
|
|
"```bash\n",
|
|
"pip install semantica\n",
|
|
"# Or with all optional dependencies:\n",
|
|
"pip install semantica[all]\n",
|
|
"```\n",
|
|
"\n",
|
|
"---\n",
|
|
"\n",
|
|
"## Step 1: Generate Embeddings\n",
|
|
"\n",
|
|
"Generate embeddings using EmbeddingGenerator.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"!pip install semantica\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from semantica.embeddings import EmbeddingGenerator\n",
|
|
"\n",
|
|
"generator = EmbeddingGenerator()\n",
|
|
"\n",
|
|
"texts = [\n",
|
|
" \"Apple Inc. is a technology company.\",\n",
|
|
" \"Microsoft Corporation develops software.\",\n",
|
|
" \"Amazon provides cloud services.\"\n",
|
|
"]\n",
|
|
"\n",
|
|
"embeddings = generator.generate_embeddings(texts, data_type=\"text\")\n",
|
|
"\n",
|
|
"print(f\"Generated embeddings for {len(texts)} texts\")\n",
|
|
"print(f\"Embeddings shape: {embeddings.shape}\")\n",
|
|
"print(f\"First embedding dimension: {len(embeddings[0]) if len(embeddings) > 0 else 'N/A'}\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Step 2: Text Embedding\n",
|
|
"\n",
|
|
"Use TextEmbedder for text-specific embeddings.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from semantica.embeddings import TextEmbedder\n",
|
|
"\n",
|
|
"text_embedder = TextEmbedder()\n",
|
|
"\n",
|
|
"text = \"Semantic knowledge graphs enable intelligent data processing.\"\n",
|
|
"\n",
|
|
"embedding = text_embedder.embed_text(text)\n",
|
|
"\n",
|
|
"print(f\"Generated embedding for text\")\n",
|
|
"print(f\"First 5 values: {embedding[:5]}\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Step 3: Model Selection & Dynamic Switching\n",
|
|
"\n",
|
|
"Semantica allows you to choose between different embedding providers (e.g., Sentence Transformers, FastEmbed) and switch models dynamically.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Initialize with a specific provider and model\n",
|
|
"embedder = TextEmbedder(method=\"sentence_transformers\", model_name=\"all-MiniLM-L6-v2\")\n",
|
|
"print(f\"Current method: {embedder.get_method()}\")\n",
|
|
"\n",
|
|
"# Switch to FastEmbed dynamically\n",
|
|
"try:\n",
|
|
" embedder.set_model(method=\"fastembed\", model_name=\"BAAI/bge-small-en-v1.5\")\n",
|
|
" print(f\"Switched to: {embedder.get_method()}\")\n",
|
|
" print(f\"Model Info: {embedder.get_model_info()}\")\n",
|
|
"except ImportError:\n",
|
|
" print(\"FastEmbed not installed. Install with: pip install fastembed\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Summary\n",
|
|
"\n",
|
|
"You've learned how to generate embeddings:\n",
|
|
"\n",
|
|
"- **EmbeddingGenerator**: Generate embeddings for multiple texts\n",
|
|
"- **TextEmbedder**: Generate text-specific embeddings\n",
|
|
"\n",
|
|
"Next: Learn how to store and search vectors in the Vector_Store notebook.\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|