rusticai-chroma 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rusticai_chroma-0.0.1/PKG-INFO +37 -0
- rusticai_chroma-0.0.1/README.md +17 -0
- rusticai_chroma-0.0.1/pyproject.toml +70 -0
- rusticai_chroma-0.0.1/src/rustic_ai/chroma/__init__.py +0 -0
- rusticai_chroma-0.0.1/src/rustic_ai/chroma/agent_ext/__init__.py +0 -0
- rusticai_chroma-0.0.1/src/rustic_ai/chroma/agent_ext/vectorstore.py +88 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rusticai-chroma
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Rustic AI module for leveraging ChromaDB
|
|
5
|
+
Home-page: https://www.rustic.ai/
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Author: Dragonscale Industries Inc.
|
|
8
|
+
Author-email: dev@dragonscale.ai
|
|
9
|
+
Requires-Python: >=3.12,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Provides-Extra: test
|
|
15
|
+
Requires-Dist: chromadb (>=1.0.3,<2.0.0)
|
|
16
|
+
Requires-Dist: rusticai-core (>=0.0.4,<0.1.0)
|
|
17
|
+
Project-URL: Repository, https://github.com/rustic-ai/python-framework
|
|
18
|
+
Project-URL: Rustic AI Core, https://pypi.org/project/rusticai-core/
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Rustic AI Chroma
|
|
22
|
+
|
|
23
|
+
This module provides a [Chroma](https://docs.trychroma.com/docs/overview/introduction) implementation of [Rustic AI](https://www.rustic.ai/)'s vectorstore.
|
|
24
|
+
|
|
25
|
+
## Installing
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
pip install rusticai-chroma
|
|
29
|
+
```
|
|
30
|
+
**Note:** It depends on [rusticai-core](https://pypi.org/project/rusticai-core/)
|
|
31
|
+
|
|
32
|
+
## Building from Source
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
poetry install --with dev
|
|
36
|
+
poetry build
|
|
37
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Rustic AI Chroma
|
|
2
|
+
|
|
3
|
+
This module provides a [Chroma](https://docs.trychroma.com/docs/overview/introduction) implementation of [Rustic AI](https://www.rustic.ai/)'s vectorstore.
|
|
4
|
+
|
|
5
|
+
## Installing
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
pip install rusticai-chroma
|
|
9
|
+
```
|
|
10
|
+
**Note:** It depends on [rusticai-core](https://pypi.org/project/rusticai-core/)
|
|
11
|
+
|
|
12
|
+
## Building from Source
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
poetry install --with dev
|
|
16
|
+
poetry build
|
|
17
|
+
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["poetry-core"]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
|
+
|
|
5
|
+
[tool.poetry]
|
|
6
|
+
name = "rusticai-chroma"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Rustic AI module for leveraging ChromaDB"
|
|
9
|
+
authors = ["Dragonscale Industries Inc. <dev@dragonscale.ai>"]
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
homepage = "https://www.rustic.ai/"
|
|
13
|
+
repository = "https://github.com/rustic-ai/python-framework"
|
|
14
|
+
packages = [{ include = "rustic_ai", from = "src" }]
|
|
15
|
+
|
|
16
|
+
[tool.poetry.urls]
|
|
17
|
+
"Rustic AI Core" = "https://pypi.org/project/rusticai-core/"
|
|
18
|
+
|
|
19
|
+
[tool.poetry.dependencies]
|
|
20
|
+
python = "^3.12"
|
|
21
|
+
rusticai-core = { version = "0.0.4"}
|
|
22
|
+
chromadb = "^1.0.3"
|
|
23
|
+
|
|
24
|
+
[tool.poetry-monorepo.deps]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
[tool.poetry.group.dev]
|
|
28
|
+
optional = true
|
|
29
|
+
|
|
30
|
+
[tool.poetry.group.dev.dependencies]
|
|
31
|
+
pytest = "^8.3.4"
|
|
32
|
+
black = { version = "^24.2.0", extras = ["jupyter"] }
|
|
33
|
+
flake8 = "^7.1.2"
|
|
34
|
+
tox = "^4.24.1"
|
|
35
|
+
isort = "^6.0.0"
|
|
36
|
+
mypy = "^1.15.0"
|
|
37
|
+
|
|
38
|
+
[tool.poetry.extras]
|
|
39
|
+
test = ["pytest"]
|
|
40
|
+
|
|
41
|
+
[tool.black]
|
|
42
|
+
line-length = 120
|
|
43
|
+
target-version = ['py312']
|
|
44
|
+
include = '\.pyi?$'
|
|
45
|
+
exclude = '''
|
|
46
|
+
/(
|
|
47
|
+
\.git
|
|
48
|
+
| \.mypy_cache
|
|
49
|
+
| \.tox
|
|
50
|
+
| \.venv
|
|
51
|
+
| _build
|
|
52
|
+
| buck-out
|
|
53
|
+
| build
|
|
54
|
+
| dist
|
|
55
|
+
)/
|
|
56
|
+
'''
|
|
57
|
+
|
|
58
|
+
[tool.mypy]
|
|
59
|
+
python_version = "3.12"
|
|
60
|
+
ignore_missing_imports = true
|
|
61
|
+
check_untyped_defs = true
|
|
62
|
+
plugins = "pydantic.mypy"
|
|
63
|
+
explicit_package_bases = true
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
[tool.isort]
|
|
67
|
+
profile = "black"
|
|
68
|
+
known_third_party = ["pydantic"]
|
|
69
|
+
known_first_party = ["rustic_ai.core"]
|
|
70
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Dict, List, Optional
|
|
3
|
+
|
|
4
|
+
import chromadb
|
|
5
|
+
|
|
6
|
+
from rustic_ai.core.agents.commons.media import Document
|
|
7
|
+
from rustic_ai.core.guild.agent_ext.depends import DependencyResolver
|
|
8
|
+
from rustic_ai.core.guild.agent_ext.depends.embeddings import Embeddings
|
|
9
|
+
from rustic_ai.core.guild.agent_ext.depends.vectorstore import (
|
|
10
|
+
UpsertResponse,
|
|
11
|
+
VectorStore,
|
|
12
|
+
)
|
|
13
|
+
from rustic_ai.core.guild.agent_ext.depends.vectorstore.vectorstore import (
|
|
14
|
+
DEFAULT_K,
|
|
15
|
+
VectorSearchResult,
|
|
16
|
+
VectorSearchResults,
|
|
17
|
+
)
|
|
18
|
+
from rustic_ai.core.utils import JsonDict
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Chroma(VectorStore):
|
|
22
|
+
def __init__(self, collection) -> None:
|
|
23
|
+
self.collection = collection
|
|
24
|
+
|
|
25
|
+
def upsert(self, documents: List[Document]) -> UpsertResponse:
|
|
26
|
+
ids = [doc.id for doc in documents]
|
|
27
|
+
texts = [doc.content for doc in documents]
|
|
28
|
+
metadatas = [doc.metadata for doc in documents]
|
|
29
|
+
|
|
30
|
+
self.collection.upsert(ids=ids, documents=texts, metadatas=metadatas)
|
|
31
|
+
return UpsertResponse(succeeded=ids, failed=[])
|
|
32
|
+
|
|
33
|
+
def delete(self, ids: Optional[List[str]] = None) -> Optional[bool]:
|
|
34
|
+
self.collection.delete(ids=ids)
|
|
35
|
+
return True
|
|
36
|
+
|
|
37
|
+
def get_by_ids(self, ids: List[str]) -> List[Document]:
|
|
38
|
+
results = self.collection.get(ids=ids)
|
|
39
|
+
docs = []
|
|
40
|
+
for i in range(len(results["ids"])):
|
|
41
|
+
docs.append(
|
|
42
|
+
Document(id=results["ids"][i], content=results["documents"][i], metadata=results["metadatas"][i])
|
|
43
|
+
)
|
|
44
|
+
return docs
|
|
45
|
+
|
|
46
|
+
def similarity_search(
|
|
47
|
+
self,
|
|
48
|
+
query: str,
|
|
49
|
+
k: int = DEFAULT_K,
|
|
50
|
+
metadata_filter: Optional[Dict[str, str]] = None,
|
|
51
|
+
where_documents: Optional[Dict[str, str]] = None,
|
|
52
|
+
) -> VectorSearchResults:
|
|
53
|
+
results = self.collection.query(query_texts=[query], n_results=k, where=metadata_filter or where_documents)
|
|
54
|
+
|
|
55
|
+
search_results = []
|
|
56
|
+
for i in range(len(results["ids"][0])):
|
|
57
|
+
doc = Document(
|
|
58
|
+
id=results["ids"][0][i], content=results["documents"][0][i], metadata=results["metadatas"][0][i]
|
|
59
|
+
)
|
|
60
|
+
score = results["distances"][0][i] if "distances" in results else 1.0
|
|
61
|
+
search_results.append(VectorSearchResult(document=doc, score=score))
|
|
62
|
+
|
|
63
|
+
return VectorSearchResults(query=query, results=search_results)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class ChromaResolver(DependencyResolver[VectorStore]):
|
|
67
|
+
def __init__(self, chroma_settings: JsonDict = {}):
|
|
68
|
+
super().__init__()
|
|
69
|
+
self.chroma_settings = chroma_settings
|
|
70
|
+
|
|
71
|
+
def resolve(self, guild_id: str, agent_id: str) -> VectorStore:
|
|
72
|
+
try:
|
|
73
|
+
embeddings: Embeddings = self.inject(Embeddings, "embeddings", guild_id, agent_id)
|
|
74
|
+
except Exception as e:
|
|
75
|
+
logging.error(f"Error creating embeddings: {e}")
|
|
76
|
+
raise
|
|
77
|
+
|
|
78
|
+
settings = chromadb.config.Settings.validate(self.chroma_settings)
|
|
79
|
+
settings.anonymized_telemetry = False
|
|
80
|
+
settings.tenant_id = guild_id
|
|
81
|
+
|
|
82
|
+
client = chromadb.Client(settings)
|
|
83
|
+
|
|
84
|
+
collection = client.get_or_create_collection(
|
|
85
|
+
name=f"rusticai_{guild_id}_{agent_id}", embedding_function=embeddings.embed
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
return Chroma(collection)
|