Skip to content

Commit

Permalink
feat: Print chroma version with every command (#120)
Browse files Browse the repository at this point in the history
Closes #106
  • Loading branch information
tazarov authored Jan 20, 2025
1 parent 0e1f1b2 commit 6efe9e5
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chroma_ops/collection_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SqliteMode,
get_sqlite_connection,
get_sqlite_snapshot_connection,
print_chroma_version,
read_script,
validate_chroma_persist_dir,
)
Expand Down Expand Up @@ -227,6 +228,7 @@ def collection_snapshot(
)
sys.exit(1)
validate_chroma_persist_dir(persist_dir)
print_chroma_version(console)
if output_file.exists():
if not yes:
if not typer.confirm(
Expand Down
2 changes: 2 additions & 0 deletions chroma_ops/db_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from chroma_ops.utils import (
SqliteMode,
get_sqlite_connection,
print_chroma_version,
validate_chroma_persist_dir,
)

Expand All @@ -17,6 +18,7 @@ def clean(persist_dir: str, yes: Optional[bool] = False) -> None:
with get_sqlite_connection(persist_dir, SqliteMode.READ_ONLY) as conn:
console = Console()
cursor = conn.cursor()
print_chroma_version(console)
console.print("Cleaning up orphanated segment dirs...")
query = "SELECT id FROM segments WHERE scope = 'VECTOR';"
cursor.execute(query)
Expand Down
2 changes: 2 additions & 0 deletions chroma_ops/db_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
SqliteMode,
list_collections,
get_sqlite_connection,
print_chroma_version,
validate_chroma_persist_dir,
get_dir_size,
decode_seq_id,
Expand All @@ -33,6 +34,7 @@ def info(
) -> Dict[str, Any]:
console = Console()
validate_chroma_persist_dir(persist_dir)
print_chroma_version(console)
export_data = {}
chroma_version = chromadb.__version__
export_data["chroma_version"] = chroma_version
Expand Down
2 changes: 2 additions & 0 deletions chroma_ops/fts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from chroma_ops.utils import (
SqliteMode,
get_sqlite_connection,
print_chroma_version,
validate_chroma_persist_dir,
read_script,
)
Expand Down Expand Up @@ -38,6 +39,7 @@ def rebuild_fts(
validate_chroma_persist_dir(persist_dir)
validate_tokenizer(tokenizer)
console = Console()
print_chroma_version(console)
if not yes:
if not typer.confirm(
f"\nAre you sure you want to rebuild the FTS index in {persist_dir}? This action will drop the existing FTS index and create a new one.",
Expand Down
4 changes: 4 additions & 0 deletions chroma_ops/hnsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SqliteMode,
check_disk_space,
get_sqlite_connection,
print_chroma_version,
validate_chroma_persist_dir,
get_dir_size,
PersistentData,
Expand Down Expand Up @@ -380,6 +381,7 @@ def rebuild_hnsw(
"""Rebuilds the HNSW index"""
validate_chroma_persist_dir(persist_dir)
console = Console()
print_chroma_version(console)
with get_sqlite_connection(persist_dir, SqliteMode.READ_WRITE) as conn:
# lock the database to ensure no new data is added while we are rebuilding the index
conn.execute("BEGIN EXCLUSIVE")
Expand Down Expand Up @@ -513,6 +515,7 @@ def info_hnsw(
) -> HnswDetails:
validate_chroma_persist_dir(persist_dir)
console = Console()
print_chroma_version(console)
with get_sqlite_connection(persist_dir, SqliteMode.READ_ONLY) as conn:
try:
hnsw_details = _get_hnsw_details(
Expand All @@ -539,6 +542,7 @@ def modify_runtime_config(
) -> None:
validate_chroma_persist_dir(persist_dir)
console = Console()
print_chroma_version(console)
with get_sqlite_connection(persist_dir, SqliteMode.READ_WRITE) as conn:
conn.execute("BEGIN EXCLUSIVE")
try:
Expand Down
8 changes: 8 additions & 0 deletions chroma_ops/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import chromadb
from chromadb import __version__ as chroma_version
import hnswlib
from rich.console import Console


def validate_chroma_persist_dir(persist_dir: str) -> None:
Expand Down Expand Up @@ -182,3 +183,10 @@ def check_disk_space(source_dir: str, target_dir: str) -> bool:
if free_space < required_space:
return False
return True


def print_chroma_version(console: Console) -> None:
"""Print the ChromaDB version"""
console.print(
f"[bold green]ChromaDB version[/bold green]: [bold blue]{chroma_version}[/bold blue]"
)
2 changes: 2 additions & 0 deletions chroma_ops/wal_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from chroma_ops.utils import (
SqliteMode,
get_sqlite_connection,
print_chroma_version,
validate_chroma_persist_dir,
get_hnsw_index_ids,
get_dir_size,
Expand All @@ -25,6 +26,7 @@ def clean_wal(
) -> None:
validate_chroma_persist_dir(persist_dir)
console = Console()
print_chroma_version(console)
console.print(f"[green]Size before: {get_dir_size(persist_dir)}[/green]")
with get_sqlite_connection(persist_dir, SqliteMode.READ_WRITE) as conn:
cursor = conn.cursor()
Expand Down
2 changes: 2 additions & 0 deletions chroma_ops/wal_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from chroma_ops.utils import (
SqliteMode,
get_sqlite_connection,
print_chroma_version,
validate_chroma_persist_dir,
)
from rich.table import Table
Expand All @@ -29,6 +30,7 @@ def commit_wal(
validate_chroma_persist_dir(persist_dir)
skip_collection_names = skip_collection_names or []
console = Console()
print_chroma_version(console)
collections_to_commit = []
vector_segments = []
skipped_collections_table = Table(title="Skipped Collections")
Expand Down
2 changes: 2 additions & 0 deletions chroma_ops/wal_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from chroma_ops.utils import (
SqliteMode,
get_sqlite_connection,
print_chroma_version,
validate_chroma_persist_dir,
)
from rich.console import Console
Expand All @@ -23,6 +24,7 @@ def config_wal(
) -> None:
validate_chroma_persist_dir(persist_dir)
console = Console()
print_chroma_version(console)
with get_sqlite_connection(persist_dir, SqliteMode.READ_WRITE) as conn:
cursor = conn.cursor()
try:
Expand Down
2 changes: 2 additions & 0 deletions chroma_ops/wal_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from chroma_ops.utils import (
SqliteMode,
get_sqlite_connection,
print_chroma_version,
validate_chroma_persist_dir,
)

Expand Down Expand Up @@ -42,6 +43,7 @@ def export_wal(
) -> None:
validate_chroma_persist_dir(persist_dir)
console = Console(stderr=True)
print_chroma_version(console)
table = Table(title="Exporting WAL")
table.add_column("Collection", style="cyan")
table.add_column("WAL Entries", style="magenta")
Expand Down
2 changes: 2 additions & 0 deletions chroma_ops/wal_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
SqliteMode,
get_sqlite_connection,
list_collections,
print_chroma_version,
validate_chroma_persist_dir,
)
from rich.console import Console
Expand All @@ -15,6 +16,7 @@
def info_wal(persist_dir: str) -> List[Tuple[str, str, int]]:
validate_chroma_persist_dir(persist_dir)
console = Console()
print_chroma_version(console)
with get_sqlite_connection(persist_dir, SqliteMode.READ_ONLY) as conn:
client = chromadb.PersistentClient(path=persist_dir)
cursor = conn.cursor()
Expand Down

0 comments on commit 6efe9e5

Please sign in to comment.