A collection of experimental Chroma extensions.
Project description
ChromaX: An experimental utilities package for Chroma vector database
Installation
pip install chromadbx
Usage
Queries
Supported filters:
$eq
- equal to (string, int, float)$ne
- not equal to (string, int, float)$gt
- greater than (int, float)$gte
- greater than or equal to (int, float)$lt
- less than (int, float)$lte
- less than or equal to (int, float)$in
- in (list of strings, ints, floats,bools)$nin
- not in (list of strings, ints, floats,bools)
Where:
import chromadb
from chromadbx.core.queries import eq, where, ne, and_
client = chromadb.PersistentClient(path="path/to/db")
collection = client.get_collection("collection_name")
collection.query(where=where(and_(eq("a", 1), ne("b", "2"))))
# {'$and': [{'a': ['$eq', 1]}, {'b': ['$ne', '2']}]}
Where Document:
import chromadb
from chromadbx.core.queries import where_document, contains, not_contains, LogicalOperator
client = chromadb.PersistentClient(path="path/to/db")
collection = client.get_collection("collection_name")
collection.query(where_document=where_document(contains("this is a document", "this is another document")))
# {'$and': [{'$contains': 'this is a document'}, {'$contains': 'this is another document'}]}
collection.query(
where_document=where_document(contains("this is a document", "this is another document", op=LogicalOperator.OR)))
# {'$or': [{'$contains': 'this is a document'}, {'$contains': 'this is another document'}]}
ID Generation
import chromadb
from chromadbx import IDGenerator
from functools import partial
from typing import Generator
def sequential_generator(start: int = 0) -> Generator[str, None, None]:
_next = start
while True:
yield f"{_next}"
_next += 1
client = chromadb.Client()
col = client.get_or_create_collection("test")
my_docs = [f"Document {_}" for _ in range(10)]
idgen = IDGenerator(len(my_docs), generator=partial(sequential_generator, start=10))
col.add(ids=idgen, documents=my_docs)
UUIDs (default)
import chromadb
from chromadbx import UUIDGenerator
client = chromadb.Client()
col = client.get_or_create_collection("test")
my_docs = [f"Document {_}" for _ in range(10)]
col.add(ids=UUIDGenerator(len(my_docs)), documents=my_docs)
ULIDs
import chromadb
from chromadbx import ULIDGenerator
import ulid
client = chromadb.Client()
col = client.get_or_create_collection("test")
my_docs = [f"Document {_}" for _ in range(10)]
col.add(ids=ULIDGenerator(len(my_docs)), documents=my_docs)
Hashes
Random SHA256:
import chromadb
from chromadbx import RandomSHA256Generator
client = chromadb.Client()
col = client.get_or_create_collection("test")
my_docs = [f"Document {_}" for _ in range(10)]
col.add(ids=RandomSHA256Generator(len(my_docs)), documents=my_docs)
Document-based SHA256:
import chromadb
from chromadbx import DocumentSHA256Generator
client = chromadb.Client()
col = client.get_or_create_collection("test")
my_docs = [f"Document {_}" for _ in range(10)]
col.add(ids=DocumentSHA256Generator(documents=my_docs), documents=my_docs)
NanoID
import chromadb
from chromadbx import NanoIDGenerator
client = chromadb.Client()
col = client.get_or_create_collection("test")
my_docs = [f"Document {_}" for _ in range(10)]
col.add(ids=NanoIDGenerator(len(my_docs)), documents=my_docs)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
chromadbx-0.0.3.tar.gz
(4.8 kB
view details)
Built Distribution
File details
Details for the file chromadbx-0.0.3.tar.gz
.
File metadata
- Download URL: chromadbx-0.0.3.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1023-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f92540818f58af1d26b0a0707a39747bc4d8b538ff43dd7fe9274e4aaee2436e |
|
MD5 | dc89f5e49ffa486d7bdfd5ca935a6b88 |
|
BLAKE2b-256 | 44d325e810f3ddb0cca93b7555cce0c88f54ed0f04e7f6019360d49a6e6c5db4 |
File details
Details for the file chromadbx-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: chromadbx-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1023-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 219f2327e1ea306fda041e0ec75c7870b2d881b05fecba40f95ebc93a626b752 |
|
MD5 | f591544ec9e22ad9c62bf096059e05eb |
|
BLAKE2b-256 | 706dc26ea3a82939b12f4608cee5bed8cb33b4490b2d781acf9a6d109f7f808e |