Chroma Embeddings Aggregation Library
This Python library provides a suite of advanced methods for aggregating multiple embeddings associated with a single document or entity into a single representative embedding. It is designed to work with Chroma vector stores and is compatible with LangChain's Chroma integration.
Table of Contents
Features
- Multiple aggregation methods (average, weighted average, geometric mean, harmonic mean, centroid, PCA, etc.)
- Compatible with Chroma vector stores and LangChain
- Easy-to-use API for aggregating embeddings
Installation
To install the package, you can use pip:
pip install chroma_vector_aggregator
Usage
Here's an example demonstrating how to use the library to aggregate embeddings using simple averaging:
Example: Simple Average Aggregation
from langchain_community.vectorstores import Chroma
from langchain_community.embeddings import FakeEmbeddings
from langchain.schema import Document
from chroma_vector_aggregator import aggregate_embeddings
# Create a sample Chroma collection
embeddings = FakeEmbeddings(size=10)
documents = [
Document(page_content="Test document 1", metadata={"id": "group1"}),
Document(page_content="Test document 2", metadata={"id": "group1"}),
Document(page_content="Test document 3", metadata={"id": "group2"}),
Document(page_content="Test document 4", metadata={"id": "group2"}),
]
chroma_collection = Chroma.from_documents(documents, embeddings)
# Aggregate embeddings using simple averaging
aggregated_collection = aggregate_embeddings(
chroma_collection=chroma_collection,
column_name="id",
method="average"
)
# Use the aggregated collection for similarity search
results = aggregated_collection.similarity_search("Test query", k=2)
Aggregation Methods
average: Compute the arithmetic mean of embeddings.weighted_average: Compute a weighted average of embeddings.geometric_mean: Compute the geometric mean across embeddings.harmonic_mean: Compute the harmonic mean across embeddings.median: Compute the element-wise median of embeddings.trimmed_mean: Compute the mean after trimming outliers.centroid: Use K-Means clustering to find the centroid of the embeddings.pca: Use Principal Component Analysis to reduce embeddings.exemplar: Select the embedding that best represents the group.max_pooling: Take the maximum value for each dimension across embeddings.min_pooling: Take the minimum value for each dimension across embeddings.entropy_weighted_average: Weight embeddings by their entropy.attentive_pooling: Use an attention mechanism to aggregate embeddings.tukeys_biweight: A robust method to down-weight outliers.
Parameters
chroma_collection: The Chroma collection to aggregate embeddings from.column_name: The metadata field by which to aggregate embeddings (e.g., 'id').method: The aggregation method to use.weights(optional): Weights for theweighted_averagemethod.trim_percentage(optional): Fraction to trim from each end fortrimmed_mean.
Dependencies
- chromadb
- numpy
- scipy
- scikit-learn
- langchain
Contributing
Contributions are welcome! Please feel free to submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for chroma-vector-aggregator 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chroma_vector_aggregator-0.1.0.tar.gz | 6.1 kB | Without provenance | Details for chroma_vector_aggregator-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chroma_vector_aggregator-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for chroma_vector_aggregator-0.1.0-py3-none-any.whl |
Total release size: 13.6 kB
Release files / chroma_vector_aggregator-0.1.0.tar.gz
| Download URL | chroma_vector_aggregator-0.1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
888568a2fa98864d515e7393c6f09f24aca7b290087e75e3f4a45eac93601a87
|
|
BLAKE2b-256 checksum How to use checksums |
6fbc8b0a01a52d177cda98583bfa649504a4d7cf1dc1bce3a75bd53ea09d658f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Release files / chroma_vector_aggregator-0.1.0-py3-none-any.whl
| Download URL | chroma_vector_aggregator-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb5b7a3ce0a2c291e1a895abdcaf259254d013485fee567e907e697901e15df0
|
|
BLAKE2b-256 checksum How to use checksums |
2a4783a2495ba4acc2eff18be1d1d0bffa464939886d0282f2cf2ae5c0d4971b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Security for chroma-vector-aggregator 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.