Skip to content

Commit bf27926

Browse files
authored
Merge branch 'meta-llama:main' into main
2 parents 167c8aa + cd8715d commit bf27926

File tree

33 files changed

+1353
-658
lines changed

33 files changed

+1353
-658
lines changed

docs/source/providers/vector_io/inline_chromadb.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ See [Chroma's documentation](https://docs.trychroma.com/docs/overview/introducti
4242
| Field | Type | Required | Default | Description |
4343
|-------|------|----------|---------|-------------|
4444
| `db_path` | `<class 'str'>` | No | PydanticUndefined | |
45+
| `kvstore` | `utils.kvstore.config.RedisKVStoreConfig \| utils.kvstore.config.SqliteKVStoreConfig \| utils.kvstore.config.PostgresKVStoreConfig \| utils.kvstore.config.MongoDBKVStoreConfig` | No | sqlite | Config for KV store backend |
4546

4647
## Sample Configuration
4748

4849
```yaml
4950
db_path: ${env.CHROMADB_PATH}
51+
kvstore:
52+
type: sqlite
53+
db_path: ${env.SQLITE_STORE_DIR:=~/.llama/dummy}/chroma_inline_registry.db
5054

5155
```
5256

docs/source/providers/vector_io/remote_chromadb.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ See [Chroma's documentation](https://docs.trychroma.com/docs/overview/introducti
4141
| Field | Type | Required | Default | Description |
4242
|-------|------|----------|---------|-------------|
4343
| `url` | `str \| None` | No | PydanticUndefined | |
44+
| `kvstore` | `utils.kvstore.config.RedisKVStoreConfig \| utils.kvstore.config.SqliteKVStoreConfig \| utils.kvstore.config.PostgresKVStoreConfig \| utils.kvstore.config.MongoDBKVStoreConfig` | No | sqlite | Config for KV store backend |
4445

4546
## Sample Configuration
4647

4748
```yaml
4849
url: ${env.CHROMADB_URL}
50+
kvstore:
51+
type: sqlite
52+
db_path: ${env.SQLITE_STORE_DIR:=~/.llama/dummy}/chroma_remote_registry.db
4953

5054
```
5155

llama_stack/apis/tools/rag_tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the terms described in the LICENSE file in
55
# the root directory of this source tree.
66

7-
from enum import Enum
7+
from enum import Enum, StrEnum
88
from typing import Annotated, Any, Literal, Protocol
99

1010
from pydantic import BaseModel, Field, field_validator
@@ -88,7 +88,7 @@ class RAGQueryGenerator(Enum):
8888

8989

9090
@json_schema_type
91-
class RAGSearchMode(Enum):
91+
class RAGSearchMode(StrEnum):
9292
"""
9393
Search modes for RAG query retrieval:
9494
- VECTOR: Uses vector similarity search for semantic matching

llama_stack/distribution/build_container.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,20 @@ EOF
136136
# Add pip dependencies first since llama-stack is what will change most often
137137
# so we can reuse layers.
138138
if [ -n "$pip_dependencies" ]; then
139+
read -ra pip_args <<< "$pip_dependencies"
140+
quoted_deps=$(printf " %q" "${pip_args[@]}")
139141
add_to_container << EOF
140-
RUN $MOUNT_CACHE uv pip install $pip_dependencies
142+
RUN $MOUNT_CACHE uv pip install $quoted_deps
141143
EOF
142144
fi
143145

144146
if [ -n "$special_pip_deps" ]; then
145147
IFS='#' read -ra parts <<<"$special_pip_deps"
146148
for part in "${parts[@]}"; do
149+
read -ra pip_args <<< "$part"
150+
quoted_deps=$(printf " %q" "${pip_args[@]}")
147151
add_to_container <<EOF
148-
RUN $MOUNT_CACHE uv pip install $part
152+
RUN $MOUNT_CACHE uv pip install $quoted_deps
149153
EOF
150154
done
151155
fi
@@ -336,7 +340,7 @@ $CONTAINER_BINARY build \
336340
"$BUILD_CONTEXT_DIR"
337341

338342
# clean up tmp/configs
339-
rm -f "$BUILD_CONTEXT_DIR/run.yaml"
343+
rm -rf "$BUILD_CONTEXT_DIR/run.yaml" "$TEMP_DIR"
340344
set +x
341345

342346
echo "Success!"

llama_stack/providers/inline/vector_io/chroma/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ async def get_provider_impl(config: ChromaVectorIOConfig, deps: dict[Api, Any]):
1616
ChromaVectorIOAdapter,
1717
)
1818

19-
impl = ChromaVectorIOAdapter(config, deps[Api.inference])
19+
impl = ChromaVectorIOAdapter(config, deps[Api.inference], deps.get(Api.files))
2020
await impl.initialize()
2121
return impl

llama_stack/providers/inline/vector_io/chroma/config.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,25 @@
66

77
from typing import Any
88

9-
from pydantic import BaseModel
9+
from pydantic import BaseModel, Field
1010

11+
from llama_stack.providers.utils.kvstore.config import KVStoreConfig, SqliteKVStoreConfig
12+
from llama_stack.schema_utils import json_schema_type
1113

14+
15+
@json_schema_type
1216
class ChromaVectorIOConfig(BaseModel):
1317
db_path: str
18+
kvstore: KVStoreConfig = Field(description="Config for KV store backend")
1419

1520
@classmethod
16-
def sample_run_config(cls, db_path: str = "${env.CHROMADB_PATH}", **kwargs: Any) -> dict[str, Any]:
17-
return {"db_path": db_path}
21+
def sample_run_config(
22+
cls, __distro_dir__: str, db_path: str = "${env.CHROMADB_PATH}", **kwargs: Any
23+
) -> dict[str, Any]:
24+
return {
25+
"db_path": db_path,
26+
"kvstore": SqliteKVStoreConfig.sample_run_config(
27+
__distro_dir__=__distro_dir__,
28+
db_name="chroma_inline_registry.db",
29+
),
30+
}

llama_stack/providers/inline/vector_io/faiss/faiss.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -260,48 +260,3 @@ async def query_chunks(
260260
raise ValueError(f"Vector DB {vector_db_id} not found")
261261

262262
return await index.query_chunks(query, params)
263-
264-
async def _save_openai_vector_store_file(
265-
self, store_id: str, file_id: str, file_info: dict[str, Any], file_contents: list[dict[str, Any]]
266-
) -> None:
267-
"""Save vector store file data to kvstore."""
268-
assert self.kvstore is not None
269-
key = f"{OPENAI_VECTOR_STORES_FILES_PREFIX}{store_id}:{file_id}"
270-
await self.kvstore.set(key=key, value=json.dumps(file_info))
271-
content_key = f"{OPENAI_VECTOR_STORES_FILES_CONTENTS_PREFIX}{store_id}:{file_id}"
272-
await self.kvstore.set(key=content_key, value=json.dumps(file_contents))
273-
274-
async def _load_openai_vector_store_file(self, store_id: str, file_id: str) -> dict[str, Any]:
275-
"""Load vector store file metadata from kvstore."""
276-
assert self.kvstore is not None
277-
key = f"{OPENAI_VECTOR_STORES_FILES_PREFIX}{store_id}:{file_id}"
278-
stored_data = await self.kvstore.get(key)
279-
return json.loads(stored_data) if stored_data else {}
280-
281-
async def _load_openai_vector_store_file_contents(self, store_id: str, file_id: str) -> list[dict[str, Any]]:
282-
"""Load vector store file contents from kvstore."""
283-
assert self.kvstore is not None
284-
key = f"{OPENAI_VECTOR_STORES_FILES_CONTENTS_PREFIX}{store_id}:{file_id}"
285-
stored_data = await self.kvstore.get(key)
286-
return json.loads(stored_data) if stored_data else []
287-
288-
async def _update_openai_vector_store_file(self, store_id: str, file_id: str, file_info: dict[str, Any]) -> None:
289-
"""Update vector store file metadata in kvstore."""
290-
assert self.kvstore is not None
291-
key = f"{OPENAI_VECTOR_STORES_FILES_PREFIX}{store_id}:{file_id}"
292-
await self.kvstore.set(key=key, value=json.dumps(file_info))
293-
294-
async def _delete_openai_vector_store_file_from_storage(self, store_id: str, file_id: str) -> None:
295-
"""Delete vector store data from kvstore."""
296-
assert self.kvstore is not None
297-
298-
keys_to_delete = [
299-
f"{OPENAI_VECTOR_STORES_FILES_PREFIX}{store_id}:{file_id}",
300-
f"{OPENAI_VECTOR_STORES_FILES_CONTENTS_PREFIX}{store_id}:{file_id}",
301-
]
302-
for key in keys_to_delete:
303-
try:
304-
await self.kvstore.delete(key)
305-
except Exception as e:
306-
logger.warning(f"Failed to delete key {key}: {e}")
307-
continue

llama_stack/providers/inline/vector_io/sqlite_vec/sqlite_vec.py

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# the root directory of this source tree.
66

77
import asyncio
8-
import json
98
import logging
109
import re
1110
import sqlite3
@@ -506,140 +505,6 @@ async def unregister_vector_db(self, vector_db_id: str) -> None:
506505
await self.cache[vector_db_id].index.delete()
507506
del self.cache[vector_db_id]
508507

509-
async def _save_openai_vector_store_file(
510-
self, store_id: str, file_id: str, file_info: dict[str, Any], file_contents: list[dict[str, Any]]
511-
) -> None:
512-
"""Save vector store file metadata to SQLite database."""
513-
514-
def _create_or_store():
515-
connection = _create_sqlite_connection(self.config.db_path)
516-
cur = connection.cursor()
517-
try:
518-
# Create a table to persist OpenAI vector store files.
519-
cur.execute("""
520-
CREATE TABLE IF NOT EXISTS openai_vector_store_files (
521-
store_id TEXT,
522-
file_id TEXT,
523-
metadata TEXT,
524-
PRIMARY KEY (store_id, file_id)
525-
);
526-
""")
527-
cur.execute("""
528-
CREATE TABLE IF NOT EXISTS openai_vector_store_files_contents (
529-
store_id TEXT,
530-
file_id TEXT,
531-
contents TEXT,
532-
PRIMARY KEY (store_id, file_id)
533-
);
534-
""")
535-
connection.commit()
536-
cur.execute(
537-
"INSERT OR REPLACE INTO openai_vector_store_files (store_id, file_id, metadata) VALUES (?, ?, ?)",
538-
(store_id, file_id, json.dumps(file_info)),
539-
)
540-
cur.execute(
541-
"INSERT OR REPLACE INTO openai_vector_store_files_contents (store_id, file_id, contents) VALUES (?, ?, ?)",
542-
(store_id, file_id, json.dumps(file_contents)),
543-
)
544-
connection.commit()
545-
except Exception as e:
546-
logger.error(f"Error saving openai vector store file {store_id} {file_id}: {e}")
547-
raise
548-
finally:
549-
cur.close()
550-
connection.close()
551-
552-
try:
553-
await asyncio.to_thread(_create_or_store)
554-
except Exception as e:
555-
logger.error(f"Error saving openai vector store file {store_id} {file_id}: {e}")
556-
raise
557-
558-
async def _load_openai_vector_store_file(self, store_id: str, file_id: str) -> dict[str, Any]:
559-
"""Load vector store file metadata from SQLite database."""
560-
561-
def _load():
562-
connection = _create_sqlite_connection(self.config.db_path)
563-
cur = connection.cursor()
564-
try:
565-
cur.execute(
566-
"SELECT metadata FROM openai_vector_store_files WHERE store_id = ? AND file_id = ?",
567-
(store_id, file_id),
568-
)
569-
row = cur.fetchone()
570-
if row is None:
571-
return None
572-
(metadata,) = row
573-
return metadata
574-
finally:
575-
cur.close()
576-
connection.close()
577-
578-
stored_data = await asyncio.to_thread(_load)
579-
return json.loads(stored_data) if stored_data else {}
580-
581-
async def _load_openai_vector_store_file_contents(self, store_id: str, file_id: str) -> list[dict[str, Any]]:
582-
"""Load vector store file contents from SQLite database."""
583-
584-
def _load():
585-
connection = _create_sqlite_connection(self.config.db_path)
586-
cur = connection.cursor()
587-
try:
588-
cur.execute(
589-
"SELECT contents FROM openai_vector_store_files_contents WHERE store_id = ? AND file_id = ?",
590-
(store_id, file_id),
591-
)
592-
row = cur.fetchone()
593-
if row is None:
594-
return None
595-
(contents,) = row
596-
return contents
597-
finally:
598-
cur.close()
599-
connection.close()
600-
601-
stored_contents = await asyncio.to_thread(_load)
602-
return json.loads(stored_contents) if stored_contents else []
603-
604-
async def _update_openai_vector_store_file(self, store_id: str, file_id: str, file_info: dict[str, Any]) -> None:
605-
"""Update vector store file metadata in SQLite database."""
606-
607-
def _update():
608-
connection = _create_sqlite_connection(self.config.db_path)
609-
cur = connection.cursor()
610-
try:
611-
cur.execute(
612-
"UPDATE openai_vector_store_files SET metadata = ? WHERE store_id = ? AND file_id = ?",
613-
(json.dumps(file_info), store_id, file_id),
614-
)
615-
connection.commit()
616-
finally:
617-
cur.close()
618-
connection.close()
619-
620-
await asyncio.to_thread(_update)
621-
622-
async def _delete_openai_vector_store_file_from_storage(self, store_id: str, file_id: str) -> None:
623-
"""Delete vector store file metadata from SQLite database."""
624-
625-
def _delete():
626-
connection = _create_sqlite_connection(self.config.db_path)
627-
cur = connection.cursor()
628-
try:
629-
cur.execute(
630-
"DELETE FROM openai_vector_store_files WHERE store_id = ? AND file_id = ?", (store_id, file_id)
631-
)
632-
cur.execute(
633-
"DELETE FROM openai_vector_store_files_contents WHERE store_id = ? AND file_id = ?",
634-
(store_id, file_id),
635-
)
636-
connection.commit()
637-
finally:
638-
cur.close()
639-
connection.close()
640-
641-
await asyncio.to_thread(_delete)
642-
643508
async def insert_chunks(self, vector_db_id: str, chunks: list[Chunk], ttl_seconds: int | None = None) -> None:
644509
index = await self._get_and_cache_vector_db_index(vector_db_id)
645510
if not index:

llama_stack/providers/remote/vector_io/chroma/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
async def get_adapter_impl(config: ChromaVectorIOConfig, deps: dict[Api, ProviderSpec]):
1313
from .chroma import ChromaVectorIOAdapter
1414

15-
impl = ChromaVectorIOAdapter(config, deps[Api.inference])
15+
impl = ChromaVectorIOAdapter(config, deps[Api.inference], deps.get(Api.files))
1616
await impl.initialize()
1717
return impl

0 commit comments

Comments
 (0)