llamasearchai/llamamlx-embeddings

AI-powered library for the LlamaSearch ecosystem

0

stars

0

commits

Python

primary language

Apr 15, 2025

updated

README

llamamlx-embeddings

llamamlx-embeddings Logo

Tests PyPI Python Versions License codecov

High-performance embeddings with Apple MLX πŸš€
Version 0.2.0

Overview

llamamlx-embeddings is a Python library that provides high-performance text embeddings using Apple's MLX framework, optimized for Apple Silicon. It offers a unified interface for generating embeddings with various models, efficient batch processing, quantization options, seamless integration with vector databases, and easy deployment as a FastAPI service.

Project Structure

This package follows a standardized structure for ease of use and maintainability:

llamamlx-embeddings/
β”œβ”€β”€ src/                      # Source code directory
β”‚   └── llamamlx_embeddings/  # Main package
β”‚       β”œβ”€β”€ api/              # API interfaces and handlers
β”‚       β”œβ”€β”€ benchmarks/       # Benchmarking tools
β”‚       β”œβ”€β”€ core/             # Core functionality
β”‚       β”œβ”€β”€ conversion/       # Model conversion utilities
β”‚       β”œβ”€β”€ integrations/     # Vector DB integrations
β”‚       β”œβ”€β”€ processing/       # Text processing utilities
β”‚       β”œβ”€β”€ quantization/     # Model quantization tools
β”‚       β”œβ”€β”€ utils/            # Common utility functions
β”‚       β”œβ”€β”€ visualization/    # Visualization utilities
β”‚       β”œβ”€β”€ __init__.py       # Package initialization
β”‚       β”œβ”€β”€ cli.py            # Command-line interface
β”‚       β”œβ”€β”€ client.py         # API client
β”‚       β”œβ”€β”€ logging.py        # Logging configuration
β”‚       └── version.py        # Version information
β”œβ”€β”€ tests/                    # Test directory
β”œβ”€β”€ docs/                     # Documentation
β”œβ”€β”€ examples/                 # Example scripts
β”œβ”€β”€ benchmarks/               # Benchmark results
β”œβ”€β”€ setup.py                  # Package setup script
β”œβ”€β”€ pyproject.toml            # Project configuration
β”œβ”€β”€ MANIFEST.in               # Package manifest
β”œβ”€β”€ README.md                 # Project README
└── LICENSE                   # License information

What's New in v0.2.0

  • Fixed import and dependency issues
  • Improved package structure and organization
  • Added support for the renamed Pinecone package
  • Enhanced GitHub Actions workflows for testing and publishing
  • Updated build system with modern Python packaging tools
  • Added comprehensive test suite
  • Improved documentation

✨ Features

  • πŸš€ MLX Optimizations: Leverages Apple Silicon's full potential
  • 🧩 Multiple Model Types: Dense, sparse, and late interaction models
  • πŸ’» Cross-Platform: ONNX fallback for non-Apple hardware
  • πŸ” Vector DB Integration: Easy integration with Qdrant and Pinecone
  • 🌐 FastAPI Server: Ready-to-use REST API
  • πŸ“¦ Batch Processing: Efficient handling of large datasets
  • πŸ”§ Quantization: Reduce memory footprint and improve speed

πŸ“Š Benchmarks

On Apple M2 Pro, using batch size 32:

ModelTexts/secDimType
BAAI/bge-small-en-v1.5~245384Dense
sentence-transformers/all-MiniLM-L6-v2~285384Dense
intfloat/e5-small-v2~230384Dense
prithivida/Splade_PP_en_v1~80varSparse

With INT8 quantization, throughput improves by ~30% and model size reduces by ~69%

πŸ› οΈ Installation

From PyPI

# Basic installation
pip install llamamlx-embeddings

# With vector database integrations
pip install llamamlx-embeddings[qdrant,pinecone]

# Full installation with all features
pip install llamamlx-embeddings[all]

From source

git clone https://github.com/yourusername/llamamlx-embeddings.git
cd llamamlx-embeddings
pip install -e .

πŸš€ Quickstart

Basic Usage

from llamamlx_embeddings import TextEmbedding
import numpy as np

# Create an embedding model (will download if needed)
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5")

# Generate embeddings
query = "How to make a delicious pizza?"
query_embedding = model.embed_query(query)

documents = [
    "Pizza is a dish of Italian origin consisting of a usually round, flat base of leavened wheat-based dough.",
    "To make pizza, you need flour, water, yeast, salt, olive oil, tomato sauce, and cheese."
]
doc_embeddings = model.embed_documents(documents)

# Calculate similarities
for i, doc_emb in enumerate(doc_embeddings):
    similarity = np.dot(query_embedding, doc_emb) / (np.linalg.norm(query_embedding) * np.linalg.norm(doc_emb))
    print(f"Document {i+1} similarity: {similarity:.4f}")

Mock Embeddings for Testing

from llamamlx_embeddings import MockEmbedding

# Create a mock embedding model
model = MockEmbedding(dimensions=384)

# Use it like a regular embedding model
query_embedding = model.embed_query("How to make pizza?")
document_embeddings = model.embed_documents(["Document 1", "Document 2"])

# Perfect for testing applications without downloading large models

API Server

Start the server:

llamamlx-embeddings serve --host 0.0.0.0 --port 8000

Use the client:

from llamamlx_embeddings import LlamamlxEmbeddingsClient

# Create a client
client = LlamamlxEmbeddingsClient(base_url="http://localhost:8000")

# Generate embeddings
query = "How to make a delicious pizza?"
query_embedding = client.get_embeddings(query, is_query=True)[0]

documents = [
    "Pizza is a dish of Italian origin consisting of a usually round, flat base of leavened wheat-based dough.",
    "To make pizza, you need flour, water, yeast, salt, olive oil, tomato sauce, and cheese."
]
doc_embeddings = client.get_embeddings(documents)

πŸ“š Documentation

For comprehensive documentation, visit our documentation site.

🧩 Supported Models

  • Dense models:

    • BAAI/bge-small-en-v1.5 (default)
    • intfloat/e5-small-v2
    • sentence-transformers/all-MiniLM-L6-v2
    • and more...
  • Sparse models:

    • prithivida/Splade_PP_en_v1
  • Late interaction models:

    • colbert-ir/colbertv2.0
  • Cross-encoder models:

    • Xenova/ms-marco-MiniLM-L-6-v2

πŸ” Vector Database Integration

Qdrant

from llamamlx_embeddings import TextEmbedding, QdrantClient

# Create embedding model
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5")

# Initialize Qdrant client
vector_db = QdrantClient(
    url="https://your-qdrant-instance.com",
    collection_name="my_collection",
    embedding_model=model
)

# Add documents
vector_db.add(
    documents=["Document 1 text", "Document 2 text"],
    metadata=[{"source": "file1.txt"}, {"source": "file2.txt"}]
)

# Search with query
results = vector_db.query("My search query", limit=5)

πŸ”§ Advanced Usage

Quantization

from llamamlx_embeddings import TextEmbedding

# Load a quantized model
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5", quantize=True)

# Query and document embeddings work the same way
query_embedding = model.embed_query("How to make pizza?")

Custom Models

from llamamlx_embeddings import add_custom_model, TextEmbedding

# Add a custom model
add_custom_model(
    model_name="my-custom-model",
    model_path="/path/to/model/files",
    model_type="dense",
    dimensions=768,
    description="My custom embedding model"
)

# Use the custom model
model = TextEmbedding(model_name="my-custom-model")

🀝 Contributing

Contributions are welcome! Please check out our contributing guide to get started.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

Updated in commit 1 - 2025-04-04 17:15:20

Updated in commit 9 - 2025-04-04 17:15:21

Updated in commit 17 - 2025-04-04 17:15:22

Updated in commit 25 - 2025-04-04 17:15:23

Updated in commit 1 - 2025-04-05 14:29:28

Updated in commit 9 - 2025-04-05 14:29:28

Updated in commit 17 - 2025-04-05 14:29:28

Updated in commit 25 - 2025-04-05 14:29:28

Updated in commit 1 - 2025-04-05 15:15:39

Updated in commit 9 - 2025-04-05 15:15:39

Updated in commit 17 - 2025-04-05 15:15:39

Updated in commit 25 - 2025-04-05 15:15:39

Updated in commit 1 - 2025-04-05 15:46:38

Updated in commit 9 - 2025-04-05 15:46:38

Updated in commit 17 - 2025-04-05 15:46:38

Updated in commit 25 - 2025-04-05 15:46:38

Updated in commit 1 - 2025-04-05 16:51:37

Updated in commit 9 - 2025-04-05 16:51:38

Updated in commit 17 - 2025-04-05 16:51:38

Updated in commit 25 - 2025-04-05 16:51:38

Updated in commit 1 - 2025-04-05 17:23:36

Updated in commit 9 - 2025-04-05 17:23:36

Updated in commit 17 - 2025-04-05 17:23:36

Updated in commit 25 - 2025-04-05 17:23:36

Updated in commit 1 - 2025-04-05 18:10:45

Updated in commit 9 - 2025-04-05 18:10:45

Updated in commit 17 - 2025-04-05 18:10:45

Updated in commit 25 - 2025-04-05 18:10:45

Updated in commit 1 - 2025-04-05 18:34:44

Updated in commit 9 - 2025-04-05 18:34:45

Updated in commit 17 - 2025-04-05 18:34:45

Updated in commit 25 - 2025-04-05 18:34:45

llamasearchai/llamamlx-embeddings

AI-powered library for the LlamaSearch ecosystem

0

stars

0

commits

Python

primary language

Apr 15, 2025

updated

README

llamamlx-embeddings

llamamlx-embeddings Logo

Tests PyPI Python Versions License codecov

High-performance embeddings with Apple MLX πŸš€
Version 0.2.0

Overview

llamamlx-embeddings is a Python library that provides high-performance text embeddings using Apple's MLX framework, optimized for Apple Silicon. It offers a unified interface for generating embeddings with various models, efficient batch processing, quantization options, seamless integration with vector databases, and easy deployment as a FastAPI service.

Project Structure

This package follows a standardized structure for ease of use and maintainability:

llamamlx-embeddings/
β”œβ”€β”€ src/                      # Source code directory
β”‚   └── llamamlx_embeddings/  # Main package
β”‚       β”œβ”€β”€ api/              # API interfaces and handlers
β”‚       β”œβ”€β”€ benchmarks/       # Benchmarking tools
β”‚       β”œβ”€β”€ core/             # Core functionality
β”‚       β”œβ”€β”€ conversion/       # Model conversion utilities
β”‚       β”œβ”€β”€ integrations/     # Vector DB integrations
β”‚       β”œβ”€β”€ processing/       # Text processing utilities
β”‚       β”œβ”€β”€ quantization/     # Model quantization tools
β”‚       β”œβ”€β”€ utils/            # Common utility functions
β”‚       β”œβ”€β”€ visualization/    # Visualization utilities
β”‚       β”œβ”€β”€ __init__.py       # Package initialization
β”‚       β”œβ”€β”€ cli.py            # Command-line interface
β”‚       β”œβ”€β”€ client.py         # API client
β”‚       β”œβ”€β”€ logging.py        # Logging configuration
β”‚       └── version.py        # Version information
β”œβ”€β”€ tests/                    # Test directory
β”œβ”€β”€ docs/                     # Documentation
β”œβ”€β”€ examples/                 # Example scripts
β”œβ”€β”€ benchmarks/               # Benchmark results
β”œβ”€β”€ setup.py                  # Package setup script
β”œβ”€β”€ pyproject.toml            # Project configuration
β”œβ”€β”€ MANIFEST.in               # Package manifest
β”œβ”€β”€ README.md                 # Project README
└── LICENSE                   # License information

What's New in v0.2.0

  • Fixed import and dependency issues
  • Improved package structure and organization
  • Added support for the renamed Pinecone package
  • Enhanced GitHub Actions workflows for testing and publishing
  • Updated build system with modern Python packaging tools
  • Added comprehensive test suite
  • Improved documentation

✨ Features

  • πŸš€ MLX Optimizations: Leverages Apple Silicon's full potential
  • 🧩 Multiple Model Types: Dense, sparse, and late interaction models
  • πŸ’» Cross-Platform: ONNX fallback for non-Apple hardware
  • πŸ” Vector DB Integration: Easy integration with Qdrant and Pinecone
  • 🌐 FastAPI Server: Ready-to-use REST API
  • πŸ“¦ Batch Processing: Efficient handling of large datasets
  • πŸ”§ Quantization: Reduce memory footprint and improve speed

πŸ“Š Benchmarks

On Apple M2 Pro, using batch size 32:

ModelTexts/secDimType
BAAI/bge-small-en-v1.5~245384Dense
sentence-transformers/all-MiniLM-L6-v2~285384Dense
intfloat/e5-small-v2~230384Dense
prithivida/Splade_PP_en_v1~80varSparse

With INT8 quantization, throughput improves by ~30% and model size reduces by ~69%

πŸ› οΈ Installation

From PyPI

# Basic installation
pip install llamamlx-embeddings

# With vector database integrations
pip install llamamlx-embeddings[qdrant,pinecone]

# Full installation with all features
pip install llamamlx-embeddings[all]

From source

git clone https://github.com/yourusername/llamamlx-embeddings.git
cd llamamlx-embeddings
pip install -e .

πŸš€ Quickstart

Basic Usage

from llamamlx_embeddings import TextEmbedding
import numpy as np

# Create an embedding model (will download if needed)
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5")

# Generate embeddings
query = "How to make a delicious pizza?"
query_embedding = model.embed_query(query)

documents = [
    "Pizza is a dish of Italian origin consisting of a usually round, flat base of leavened wheat-based dough.",
    "To make pizza, you need flour, water, yeast, salt, olive oil, tomato sauce, and cheese."
]
doc_embeddings = model.embed_documents(documents)

# Calculate similarities
for i, doc_emb in enumerate(doc_embeddings):
    similarity = np.dot(query_embedding, doc_emb) / (np.linalg.norm(query_embedding) * np.linalg.norm(doc_emb))
    print(f"Document {i+1} similarity: {similarity:.4f}")

Mock Embeddings for Testing

from llamamlx_embeddings import MockEmbedding

# Create a mock embedding model
model = MockEmbedding(dimensions=384)

# Use it like a regular embedding model
query_embedding = model.embed_query("How to make pizza?")
document_embeddings = model.embed_documents(["Document 1", "Document 2"])

# Perfect for testing applications without downloading large models

API Server

Start the server:

llamamlx-embeddings serve --host 0.0.0.0 --port 8000

Use the client:

from llamamlx_embeddings import LlamamlxEmbeddingsClient

# Create a client
client = LlamamlxEmbeddingsClient(base_url="http://localhost:8000")

# Generate embeddings
query = "How to make a delicious pizza?"
query_embedding = client.get_embeddings(query, is_query=True)[0]

documents = [
    "Pizza is a dish of Italian origin consisting of a usually round, flat base of leavened wheat-based dough.",
    "To make pizza, you need flour, water, yeast, salt, olive oil, tomato sauce, and cheese."
]
doc_embeddings = client.get_embeddings(documents)

πŸ“š Documentation

For comprehensive documentation, visit our documentation site.

🧩 Supported Models

  • Dense models:

    • BAAI/bge-small-en-v1.5 (default)
    • intfloat/e5-small-v2
    • sentence-transformers/all-MiniLM-L6-v2
    • and more...
  • Sparse models:

    • prithivida/Splade_PP_en_v1
  • Late interaction models:

    • colbert-ir/colbertv2.0
  • Cross-encoder models:

    • Xenova/ms-marco-MiniLM-L-6-v2

πŸ” Vector Database Integration

Qdrant

from llamamlx_embeddings import TextEmbedding, QdrantClient

# Create embedding model
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5")

# Initialize Qdrant client
vector_db = QdrantClient(
    url="https://your-qdrant-instance.com",
    collection_name="my_collection",
    embedding_model=model
)

# Add documents
vector_db.add(
    documents=["Document 1 text", "Document 2 text"],
    metadata=[{"source": "file1.txt"}, {"source": "file2.txt"}]
)

# Search with query
results = vector_db.query("My search query", limit=5)

πŸ”§ Advanced Usage

Quantization

from llamamlx_embeddings import TextEmbedding

# Load a quantized model
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5", quantize=True)

# Query and document embeddings work the same way
query_embedding = model.embed_query("How to make pizza?")

Custom Models

from llamamlx_embeddings import add_custom_model, TextEmbedding

# Add a custom model
add_custom_model(
    model_name="my-custom-model",
    model_path="/path/to/model/files",
    model_type="dense",
    dimensions=768,
    description="My custom embedding model"
)

# Use the custom model
model = TextEmbedding(model_name="my-custom-model")

🀝 Contributing

Contributions are welcome! Please check out our contributing guide to get started.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

Updated in commit 1 - 2025-04-04 17:15:20

Updated in commit 9 - 2025-04-04 17:15:21

Updated in commit 17 - 2025-04-04 17:15:22

Updated in commit 25 - 2025-04-04 17:15:23

Updated in commit 1 - 2025-04-05 14:29:28

Updated in commit 9 - 2025-04-05 14:29:28

Updated in commit 17 - 2025-04-05 14:29:28

Updated in commit 25 - 2025-04-05 14:29:28

Updated in commit 1 - 2025-04-05 15:15:39

Updated in commit 9 - 2025-04-05 15:15:39

Updated in commit 17 - 2025-04-05 15:15:39

Updated in commit 25 - 2025-04-05 15:15:39

Updated in commit 1 - 2025-04-05 15:46:38

Updated in commit 9 - 2025-04-05 15:46:38

Updated in commit 17 - 2025-04-05 15:46:38

Updated in commit 25 - 2025-04-05 15:46:38

Updated in commit 1 - 2025-04-05 16:51:37

Updated in commit 9 - 2025-04-05 16:51:38

Updated in commit 17 - 2025-04-05 16:51:38

Updated in commit 25 - 2025-04-05 16:51:38

Updated in commit 1 - 2025-04-05 17:23:36

Updated in commit 9 - 2025-04-05 17:23:36

Updated in commit 17 - 2025-04-05 17:23:36

Updated in commit 25 - 2025-04-05 17:23:36

Updated in commit 1 - 2025-04-05 18:10:45

Updated in commit 9 - 2025-04-05 18:10:45

Updated in commit 17 - 2025-04-05 18:10:45

Updated in commit 25 - 2025-04-05 18:10:45

Updated in commit 1 - 2025-04-05 18:34:44

Updated in commit 9 - 2025-04-05 18:34:45

Updated in commit 17 - 2025-04-05 18:34:45

Updated in commit 25 - 2025-04-05 18:34:45

Languages

Python

99.2%