Skip to content

Commit

Permalink
feat: Updated the memory cleanup example
Browse files Browse the repository at this point in the history
- Added config options (no descriptions and values yet)
  • Loading branch information
tazarov committed Jun 1, 2024
1 parent fbe136b commit 1cf5462
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 30 deletions.
87 changes: 87 additions & 0 deletions docs/core/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,97 @@

## Server Configuration

### Core

#### `is_persistent`

#### `persist_directory`

#### `allow_reset`

#### `chroma_memory_limit_bytes`

#### `chroma_segment_cache_policy`

### Telemetry and Observability

#### `chroma_otel_collection_endpoint`

#### `chroma_otel_service_name`

#### `chroma_otel_collection_headers`

#### `chroma_otel_granularity`

#### `chroma_product_telemetry_impl`

#### `chroma_telemetry_impl`

#### `anonymized_telemetry`

### Maintenance

#### `migrations`

#### `migrations_hash_algorithm`

### Operations and Distributed

#### `chroma_sysdb_impl`

#### `chroma_producer_impl`

#### `chroma_consumer_impl`

#### `chroma_segment_manager_impl`

#### `chroma_segment_directory_impl`

#### `chroma_memberlist_provider_impl`

#### `worker_memberlist_name`

#### `chroma_coordinator_host`

#### `chroma_server_grpc_port`

#### `chroma_logservice_host`

#### `chroma_logservice_port`

#### `chroma_quota_provider_impl`

#### `chroma_rate_limiting_provider_impl`

### Authentication

#### `chroma_auth_token_transport_header`

#### `chroma_client_auth_provider`

#### `chroma_client_auth_credentials`

#### `chroma_server_auth_ignore_paths`

#### `chroma_overwrite_singleton_tenant_database_access_from_auth`

#### `chroma_server_authn_provider`

#### `chroma_server_authn_credentials`

#### `chroma_server_authn_credentials_file`




### Authorization

#### `chroma_server_authz_provider`

#### `chroma_server_authz_config`

#### `chroma_server_authz_config_file`

## Client Configuration

### Authentication
Expand Down
64 changes: 34 additions & 30 deletions docs/strategies/memory-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,55 +46,59 @@ Here we provide a simple utility function to help users unload collections from

```python
import gc
import os

import chromadb
from chromadb.segment import VectorReader
import psutil
from chromadb.types import SegmentScope


def delete_all_references(obj):
referrers = gc.get_referrers(obj)
for referrer in referrers:
if isinstance(referrer, dict):
keys = list(referrer.keys())
for key in keys:
if referrer[key] is obj:
del referrer[key]
elif isinstance(referrer, list):
while obj in referrer:
referrer.remove(obj)
elif isinstance(referrer, set):
referrer.discard(obj)
elif isinstance(referrer, tuple):
# Tuples are immutable; cannot delete references from them
pass


def unload_index(collection_name: str, chroma_client: chromadb.PersistentClient, m_collection: chromadb.Collection):
def bytes_to_gb(bytes_value):
return bytes_value / (1024 ** 3)


def get_process_info():
pid = os.getpid()
p = psutil.Process(pid)
with p.oneshot():
mem_info = p.memory_info()
# disk_io = p.io_counters()
return {
"memory_usage": bytes_to_gb(mem_info.rss),
}


def unload_index(collection_name: str, chroma_client: chromadb.PersistentClient):
"""
Unloads binary hnsw index from memory and removes both segments (binary and metadata) from the segment cache.
"""
collection = chroma_client.get_collection(collection_name)
collection_id = collection.id

segment_manager = chroma_client._server._manager
segment = segment_manager.get_segment(collection_id, VectorReader)

segment.close_persistent_index()

# Check and remove segments based on the segment scope
for scope in [SegmentScope.VECTOR, SegmentScope.METADATA]:
if scope in segment_manager.segment_cache:
cache = segment_manager.segment_cache[scope].cache
if collection_id in cache:
del cache[collection_id]

delete_all_references(collection)
segment_manager.callback_cache_evict(cache[collection_id])
gc.collect()
gc.collect() # Call multiple times to ensure complete cleanup
```

!!! abstract "Example Contributed"

The above example was enhanced and contributed by `Amir` (amdeilami) from our Discord comminity.
We appreciate and encourage his work and contributions to the Chroma community.


??? example "Usage Example"

```python
import chromadb


client = chromadb.PersistentClient(path="testds-1M/chroma-data")
col=client.get_collection("test")
print(col.count())
col.get(limit=1,include=["embeddings"]) # force load the collection into memory

unload_index("test", client)
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ markdown_extensions:
- attr_list
- md_in_html
- markdown.extensions.extra
- pymdownx.details
- toc:
permalink: true
title: On this page
Expand Down

0 comments on commit 1cf5462

Please sign in to comment.