12
12
import chromadb
13
13
from numpy .typing import NDArray
14
14
15
+ from llama_stack .apis .files import Files
15
16
from llama_stack .apis .inference import InterleavedContent
16
17
from llama_stack .apis .vector_dbs import VectorDB
17
18
from llama_stack .apis .vector_io import (
18
19
Chunk ,
19
20
QueryChunksResponse ,
20
- SearchRankingOptions ,
21
21
VectorIO ,
22
- VectorStoreChunkingStrategy ,
23
- VectorStoreDeleteResponse ,
24
- VectorStoreFileContentsResponse ,
25
- VectorStoreFileObject ,
26
- VectorStoreFileStatus ,
27
- VectorStoreListFilesResponse ,
28
- VectorStoreListResponse ,
29
- VectorStoreObject ,
30
- VectorStoreSearchResponsePage ,
31
22
)
32
23
from llama_stack .providers .datatypes import Api , VectorDBsProtocolPrivate
33
24
from llama_stack .providers .inline .vector_io .chroma import ChromaVectorIOConfig as InlineChromaVectorIOConfig
25
+ from llama_stack .providers .utils .kvstore import kvstore_impl
26
+ from llama_stack .providers .utils .kvstore .api import KVStore
27
+ from llama_stack .providers .utils .memory .openai_vector_store_mixin import OpenAIVectorStoreMixin
34
28
from llama_stack .providers .utils .memory .vector_store import (
35
29
EmbeddingIndex ,
36
30
VectorDBWithIndex ,
42
36
43
37
ChromaClientType = chromadb .api .AsyncClientAPI | chromadb .api .ClientAPI
44
38
39
+ VERSION = "v3"
40
+ VECTOR_DBS_PREFIX = f"vector_dbs:chroma:{ VERSION } ::"
41
+ VECTOR_INDEX_PREFIX = f"vector_index:chroma:{ VERSION } ::"
42
+ OPENAI_VECTOR_STORES_PREFIX = f"openai_vector_stores:chroma:{ VERSION } ::"
43
+ OPENAI_VECTOR_STORES_FILES_PREFIX = f"openai_vector_stores_files:chroma:{ VERSION } ::"
44
+ OPENAI_VECTOR_STORES_FILES_CONTENTS_PREFIX = f"openai_vector_stores_files_contents:chroma:{ VERSION } ::"
45
+
45
46
46
47
# this is a helper to allow us to use async and non-async chroma clients interchangeably
47
48
async def maybe_await (result ):
@@ -51,9 +52,10 @@ async def maybe_await(result):
51
52
52
53
53
54
class ChromaIndex (EmbeddingIndex ):
54
- def __init__ (self , client : ChromaClientType , collection ):
55
+ def __init__ (self , client : ChromaClientType , collection , kvstore : KVStore | None = None ):
55
56
self .client = client
56
57
self .collection = collection
58
+ self .kvstore = kvstore
57
59
58
60
async def add_chunks (self , chunks : list [Chunk ], embeddings : NDArray ):
59
61
assert len (chunks ) == len (embeddings ), (
@@ -122,24 +124,23 @@ async def query_hybrid(
122
124
raise NotImplementedError ("Hybrid search is not supported in Chroma" )
123
125
124
126
125
- class ChromaVectorIOAdapter (VectorIO , VectorDBsProtocolPrivate ):
127
+ class ChromaVectorIOAdapter (OpenAIVectorStoreMixin , VectorIO , VectorDBsProtocolPrivate ):
126
128
def __init__ (
127
129
self ,
128
130
config : RemoteChromaVectorIOConfig | InlineChromaVectorIOConfig ,
129
131
inference_api : Api .inference ,
132
+ files_api : Files | None ,
130
133
) -> None :
131
134
log .info (f"Initializing ChromaVectorIOAdapter with url: { config } " )
132
135
self .config = config
133
136
self .inference_api = inference_api
134
-
135
137
self .client = None
136
138
self .cache = {}
139
+ self .kvstore : KVStore | None = None
137
140
138
141
async def initialize (self ) -> None :
142
+ self .kvstore = await kvstore_impl (self .config .kvstore )
139
143
if isinstance (self .config , RemoteChromaVectorIOConfig ):
140
- if not self .config .url :
141
- raise ValueError ("URL is a required parameter for the remote Chroma provider's config" )
142
-
143
144
log .info (f"Connecting to Chroma server at: { self .config .url } " )
144
145
url = self .config .url .rstrip ("/" )
145
146
parsed = urlparse (url )
@@ -151,6 +152,7 @@ async def initialize(self) -> None:
151
152
else :
152
153
log .info (f"Connecting to Chroma local db at: { self .config .db_path } " )
153
154
self .client = chromadb .PersistentClient (path = self .config .db_path )
155
+ self .openai_vector_stores = await self ._load_openai_vector_stores ()
154
156
155
157
async def shutdown (self ) -> None :
156
158
pass
@@ -206,107 +208,3 @@ async def _get_and_cache_vector_db_index(self, vector_db_id: str) -> VectorDBWit
206
208
index = VectorDBWithIndex (vector_db , ChromaIndex (self .client , collection ), self .inference_api )
207
209
self .cache [vector_db_id ] = index
208
210
return index
209
-
210
- async def openai_create_vector_store (
211
- self ,
212
- name : str ,
213
- file_ids : list [str ] | None = None ,
214
- expires_after : dict [str , Any ] | None = None ,
215
- chunking_strategy : dict [str , Any ] | None = None ,
216
- metadata : dict [str , Any ] | None = None ,
217
- embedding_model : str | None = None ,
218
- embedding_dimension : int | None = 384 ,
219
- provider_id : str | None = None ,
220
- ) -> VectorStoreObject :
221
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
222
-
223
- async def openai_list_vector_stores (
224
- self ,
225
- limit : int | None = 20 ,
226
- order : str | None = "desc" ,
227
- after : str | None = None ,
228
- before : str | None = None ,
229
- ) -> VectorStoreListResponse :
230
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
231
-
232
- async def openai_retrieve_vector_store (
233
- self ,
234
- vector_store_id : str ,
235
- ) -> VectorStoreObject :
236
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
237
-
238
- async def openai_update_vector_store (
239
- self ,
240
- vector_store_id : str ,
241
- name : str | None = None ,
242
- expires_after : dict [str , Any ] | None = None ,
243
- metadata : dict [str , Any ] | None = None ,
244
- ) -> VectorStoreObject :
245
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
246
-
247
- async def openai_delete_vector_store (
248
- self ,
249
- vector_store_id : str ,
250
- ) -> VectorStoreDeleteResponse :
251
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
252
-
253
- async def openai_search_vector_store (
254
- self ,
255
- vector_store_id : str ,
256
- query : str | list [str ],
257
- filters : dict [str , Any ] | None = None ,
258
- max_num_results : int | None = 10 ,
259
- ranking_options : SearchRankingOptions | None = None ,
260
- rewrite_query : bool | None = False ,
261
- search_mode : str | None = "vector" ,
262
- ) -> VectorStoreSearchResponsePage :
263
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
264
-
265
- async def openai_attach_file_to_vector_store (
266
- self ,
267
- vector_store_id : str ,
268
- file_id : str ,
269
- attributes : dict [str , Any ] | None = None ,
270
- chunking_strategy : VectorStoreChunkingStrategy | None = None ,
271
- ) -> VectorStoreFileObject :
272
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
273
-
274
- async def openai_list_files_in_vector_store (
275
- self ,
276
- vector_store_id : str ,
277
- limit : int | None = 20 ,
278
- order : str | None = "desc" ,
279
- after : str | None = None ,
280
- before : str | None = None ,
281
- filter : VectorStoreFileStatus | None = None ,
282
- ) -> VectorStoreListFilesResponse :
283
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
284
-
285
- async def openai_retrieve_vector_store_file (
286
- self ,
287
- vector_store_id : str ,
288
- file_id : str ,
289
- ) -> VectorStoreFileObject :
290
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
291
-
292
- async def openai_retrieve_vector_store_file_contents (
293
- self ,
294
- vector_store_id : str ,
295
- file_id : str ,
296
- ) -> VectorStoreFileContentsResponse :
297
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
298
-
299
- async def openai_update_vector_store_file (
300
- self ,
301
- vector_store_id : str ,
302
- file_id : str ,
303
- attributes : dict [str , Any ] | None = None ,
304
- ) -> VectorStoreFileObject :
305
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
306
-
307
- async def openai_delete_vector_store_file (
308
- self ,
309
- vector_store_id : str ,
310
- file_id : str ,
311
- ) -> VectorStoreFileObject :
312
- raise NotImplementedError ("OpenAI Vector Stores API is not supported in Chroma" )
0 commit comments