@ia-ccun/code-agent-cli 0.0.52-release → 0.0.53-beta.1
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.
- package/bin/cli.js +6 -2
- package/config/agent/bin/README.md +102 -0
- package/config/agent/extensions/aicode-advisor.ts +13 -0
- package/config/agent/extensions/aicode-btw.ts +66 -14
- package/config/agent/extensions/aicode-cd.ts +834 -0
- package/config/agent/extensions/aicode-grillMe.ts +198 -0
- package/config/agent/extensions/aicode-pets.ts +362 -0
- package/config/agent/extensions/aicode-safety-guard.ts +552 -0
- package/config/agent/extensions/aicode-tips.ts +70 -16
- package/config/agent/extensions/aicode-todo-progress.ts +547 -0
- package/config/agent/extensions/custom.ts +93 -95
- package/config/agent/extensions/error-monitor.ts +1 -18
- package/config/agent/extensions/ponytail.ts +441 -0
- package/config/agent/extensions/tps.ts +87 -0
- package/config/agent/extensions/working-msg.ts +165 -50
- package/config/agent/help.md +0 -7
- package/config/agent/models.json +7 -7
- package/config/agent/settings.json +2 -1
- package/config/agent/skills/chroma/LICENSE +21 -0
- package/config/agent/skills/chroma/chroma-local/SKILL.md +165 -0
- package/config/agent/skills/chroma/chroma-local/cli.md +48 -0
- package/config/agent/skills/chroma/chroma-local/data-model.md +103 -0
- package/config/agent/skills/chroma/chroma-local/error-handling/python.md +166 -0
- package/config/agent/skills/chroma/chroma-local/error-handling/typescript.md +231 -0
- package/config/agent/skills/chroma/chroma-local/local-chroma/python.md +95 -0
- package/config/agent/skills/chroma/chroma-local/local-chroma/typescript.md +101 -0
- package/config/agent/skills/chroma/chroma-local/metadata/python.md +154 -0
- package/config/agent/skills/chroma/chroma-local/metadata/typescript.md +153 -0
- package/config/agent/skills/chroma/chroma-local/querying/python.md +147 -0
- package/config/agent/skills/chroma/chroma-local/querying/typescript.md +157 -0
- package/config/agent/skills/chroma/chroma-local/regex/python.md +69 -0
- package/config/agent/skills/chroma/chroma-local/regex/typescript.md +71 -0
- package/config/agent/skills/chroma/chroma-local/understanding-a-codebase.md +80 -0
- package/config/agent/skills/chroma/chroma-local/updating-deleting/python.md +159 -0
- package/config/agent/skills/chroma/chroma-local/updating-deleting/typescript.md +228 -0
- package/config/agent/skills/milvus-skill/LICENSE +202 -0
- package/config/agent/skills/milvus-skill/README.md +37 -0
- package/config/agent/skills/milvus-skill/SKILL.md +259 -0
- package/config/agent/skills/milvus-skill/references/collection.md +86 -0
- package/config/agent/skills/milvus-skill/references/database.md +24 -0
- package/config/agent/skills/milvus-skill/references/index.md +69 -0
- package/config/agent/skills/milvus-skill/references/partition.md +29 -0
- package/config/agent/skills/milvus-skill/references/patterns.md +150 -0
- package/config/agent/skills/milvus-skill/references/user-role.md +90 -0
- package/config/agent/skills/milvus-skill/references/vector.md +247 -0
- package/config/agent/skills/ponytail/SKILL.md +100 -0
- package/config/agent/skills/ponytail-audit/SKILL.md +40 -0
- package/config/agent/skills/ponytail-debt/SKILL.md +44 -0
- package/config/agent/skills/ponytail-help/SKILL.md +68 -0
- package/config/agent/skills/ponytail-review/SKILL.md +56 -0
- package/config/agent/skills/zread/README.md +115 -0
- package/config/agent/skills/zread/SKILL.md +103 -0
- package/config/agent/skills/zread/references/stdio-protocol.md +312 -0
- package/package.json +6 -5
- package/scripts/postinstall.js +58 -1
- package/scripts/regression/README.md +224 -0
- package/scripts/regression/cases/01-version-and-deps.sh +94 -0
- package/scripts/regression/cases/02-extension-loading.sh +130 -0
- package/scripts/regression/cases/03-rpc-protocol.sh +259 -0
- package/scripts/regression/cases/04-prompt-stream.sh +130 -0
- package/scripts/regression/cases/05-slash-commands-and-skills.sh +119 -0
- package/scripts/regression/cases/06-tool-execution.sh +115 -0
- package/scripts/regression/cases/07-pi-new-features.sh +141 -0
- package/scripts/regression/lib/common.sh +287 -0
- package/scripts/regression/results/.last_pid +1 -0
- package/scripts/regression/results/.last_workdir +1 -0
- package/scripts/regression/results/02-extension-loading.log +29 -0
- package/scripts/regression/results/03-prompt-stream.log +25 -0
- package/scripts/regression/results/03-rpc-protocol.log +38 -0
- package/scripts/regression/results/04-slash-commands-and-skills.log +10 -0
- package/scripts/regression/results/05-tool-execution.log +6 -0
- package/scripts/regression/results/06-pi-new-features.log +33 -0
- package/scripts/regression/run-all.sh +187 -0
- package/config/agent/dangerous-patterns.json +0 -106
- package/config/agent/extensions/bash-check.ts +0 -227
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Error Handling
|
|
3
|
+
description: Handling errors and failures when working with Chroma
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Error Handling
|
|
7
|
+
|
|
8
|
+
Local Chroma operations can fail for various reasons: the local server may not be running, collections may be missing, or input data may be invalid. This guide covers the common local error scenarios and how to handle them.
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
import json
|
|
12
|
+
import time
|
|
13
|
+
|
|
14
|
+
import chromadb
|
|
15
|
+
from chromadb.errors import NotFoundError
|
|
16
|
+
from chromadb.types import Metadata
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Error types
|
|
20
|
+
|
|
21
|
+
**Python** uses specific exception classes:
|
|
22
|
+
- `chromadb.errors.NotFoundError` - Collection, tenant, or database doesn't exist
|
|
23
|
+
- `ValueError` - Invalid collection name or duplicate creation attempt
|
|
24
|
+
|
|
25
|
+
**TypeScript** throws standard `Error` objects with descriptive messages. Check the error message to determine the cause.
|
|
26
|
+
|
|
27
|
+
### Connection errors
|
|
28
|
+
|
|
29
|
+
Connection failures occur when the client can't reach the Chroma server. This is common during startup or when network issues occur.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
def connect_with_retry(max_retries: int = 3):
|
|
33
|
+
"""Connect to a local Chroma server with exponential backoff retry."""
|
|
34
|
+
client = chromadb.HttpClient(host="localhost", port=8000)
|
|
35
|
+
|
|
36
|
+
for attempt in range(1, max_retries + 1):
|
|
37
|
+
try:
|
|
38
|
+
client.heartbeat()
|
|
39
|
+
return client
|
|
40
|
+
except Exception as e:
|
|
41
|
+
if attempt == max_retries:
|
|
42
|
+
raise ConnectionError(
|
|
43
|
+
f"Failed to connect to local Chroma after {max_retries} attempts: {e}"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
time.sleep(2 ** (attempt - 1))
|
|
47
|
+
|
|
48
|
+
raise ConnectionError("Chroma is unreachable")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Collection not found
|
|
52
|
+
|
|
53
|
+
When working with collections that may not exist, handle the `NotFoundError` (Python) or catch the error and check its message (TypeScript).
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
client = chromadb.HttpClient(host="localhost", port=8000)
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
collection = client.get_collection(name="my_collection")
|
|
60
|
+
except NotFoundError:
|
|
61
|
+
print("Collection not found, creating it...")
|
|
62
|
+
collection = client.create_collection(name="my_collection")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Safe collection access pattern
|
|
66
|
+
|
|
67
|
+
The `getOrCreateCollection` method is the recommended way to avoid "not found" errors entirely. Use `getCollection` only when you specifically need to verify a collection exists.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
client = chromadb.HttpClient(host="localhost", port=8000)
|
|
71
|
+
collection = client.get_or_create_collection(name="my_collection")
|
|
72
|
+
|
|
73
|
+
results = collection.query(
|
|
74
|
+
query_texts=["search query"],
|
|
75
|
+
n_results=5,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
if results["documents"] and len(results["documents"][0]) > 0:
|
|
79
|
+
first_doc = results["documents"][0][0]
|
|
80
|
+
else:
|
|
81
|
+
pass
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Validation errors
|
|
85
|
+
|
|
86
|
+
Chroma validates data before operations. Common validation failures include:
|
|
87
|
+
- Document content exceeding 16KB
|
|
88
|
+
- Embedding dimensions not matching the collection
|
|
89
|
+
- Metadata exceeding limits (4KB total, 32 keys max)
|
|
90
|
+
- Invalid collection names
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
client = chromadb.HttpClient(host="localhost", port=8000)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def validate_document(doc: str) -> bool:
|
|
97
|
+
byte_size = len(doc.encode("utf-8"))
|
|
98
|
+
return byte_size <= 16384
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def validate_metadata(metadata: Metadata) -> bool:
|
|
102
|
+
if len(metadata.keys()) > 32:
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
json_size = len(json.dumps(metadata).encode("utf-8"))
|
|
106
|
+
return json_size <= 4096
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def safe_add(
|
|
110
|
+
collection_name: str,
|
|
111
|
+
ids: list[str],
|
|
112
|
+
documents: list[str],
|
|
113
|
+
metadatas: list[Metadata] | None
|
|
114
|
+
) -> None:
|
|
115
|
+
for doc in documents:
|
|
116
|
+
if not validate_document(doc):
|
|
117
|
+
raise ValueError("Document exceeds 16KB limit")
|
|
118
|
+
|
|
119
|
+
if metadatas:
|
|
120
|
+
for meta in metadatas:
|
|
121
|
+
if not validate_metadata(meta):
|
|
122
|
+
raise ValueError("Metadata exceeds limits (4KB or 32 keys)")
|
|
123
|
+
|
|
124
|
+
collection = client.get_or_create_collection(name=collection_name)
|
|
125
|
+
collection.add(ids=ids, documents=documents, metadatas=metadatas)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Batch operation failures
|
|
129
|
+
|
|
130
|
+
When adding or upserting multiple documents, a single invalid document fails the entire batch. Validate data before sending, or implement retry logic for partial failures.
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
client = chromadb.HttpClient(host="localhost", port=8000)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def batch_add(
|
|
137
|
+
collection_name: str,
|
|
138
|
+
ids: list[str],
|
|
139
|
+
documents: list[str],
|
|
140
|
+
batch_size: int = 100,
|
|
141
|
+
) -> dict:
|
|
142
|
+
collection = client.get_or_create_collection(name=collection_name)
|
|
143
|
+
failures = []
|
|
144
|
+
|
|
145
|
+
for i in range(0, len(ids), batch_size):
|
|
146
|
+
batch_ids = ids[i : i + batch_size]
|
|
147
|
+
batch_docs = documents[i : i + batch_size]
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
collection.add(ids=batch_ids, documents=batch_docs)
|
|
151
|
+
except Exception as e:
|
|
152
|
+
failures.append({"index": i, "error": str(e)})
|
|
153
|
+
|
|
154
|
+
total_batches = (len(ids) + batch_size - 1) // batch_size
|
|
155
|
+
return {"total_batches": total_batches, "failures": failures}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Defensive patterns summary
|
|
159
|
+
|
|
160
|
+
| Scenario | Recommended approach |
|
|
161
|
+
|----------|---------------------|
|
|
162
|
+
| Collection access | Use `getOrCreateCollection` instead of `getCollection` |
|
|
163
|
+
| Missing data | Check results length before accessing |
|
|
164
|
+
| Connection issues | Implement retry with exponential backoff |
|
|
165
|
+
| Large batches | Validate data size before operations |
|
|
166
|
+
| Local server startup | Verify the server is running before debugging query logic |
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Error Handling
|
|
3
|
+
description: Handling errors and failures when working with Chroma
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Error Handling
|
|
7
|
+
|
|
8
|
+
Local Chroma operations can fail for various reasons: the local server may not be running, collections may be missing, or input data may be invalid. This guide covers the common local error scenarios and how to handle them.
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import { ChromaClient } from 'chromadb';
|
|
12
|
+
import { DefaultEmbeddingFunction } from '@chroma-core/default-embed';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Error types
|
|
16
|
+
|
|
17
|
+
**Python** uses specific exception classes:
|
|
18
|
+
- `chromadb.errors.NotFoundError` - Collection, tenant, or database doesn't exist
|
|
19
|
+
- `ValueError` - Invalid collection name or duplicate creation attempt
|
|
20
|
+
|
|
21
|
+
**TypeScript** throws standard `Error` objects with descriptive messages. Check the error message to determine the cause.
|
|
22
|
+
|
|
23
|
+
### Connection errors
|
|
24
|
+
|
|
25
|
+
Connection failures occur when the client can't reach the Chroma server. This is common during startup or when network issues occur.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
async function connectWithRetry(maxRetries = 3): Promise<ChromaClient> {
|
|
29
|
+
const client = new ChromaClient();
|
|
30
|
+
|
|
31
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
32
|
+
try {
|
|
33
|
+
// heartbeat() verifies the connection is working
|
|
34
|
+
await client.heartbeat();
|
|
35
|
+
return client;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (attempt === maxRetries) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Failed to connect to Chroma after ${maxRetries} attempts: ${error}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
// Exponential backoff: 1s, 2s, 4s...
|
|
43
|
+
const delay = Math.pow(2, attempt - 1) * 1000;
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error('Unreachable');
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Collection not found
|
|
52
|
+
|
|
53
|
+
When working with collections that may not exist, handle the `NotFoundError` (Python) or catch the error and check its message (TypeScript).
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const client = new ChromaClient();
|
|
57
|
+
const embeddingFunction = new DefaultEmbeddingFunction();
|
|
58
|
+
|
|
59
|
+
// getCollection throws if the collection doesn't exist
|
|
60
|
+
try {
|
|
61
|
+
const collection = await client.getCollection({
|
|
62
|
+
name: 'my_collection',
|
|
63
|
+
embeddingFunction,
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error instanceof Error && error.message.includes('does not exist')) {
|
|
67
|
+
console.log('Collection not found, creating it...');
|
|
68
|
+
// Handle missing collection
|
|
69
|
+
} else {
|
|
70
|
+
throw error; // Re-throw unexpected errors
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Safe collection access pattern
|
|
76
|
+
|
|
77
|
+
The `getOrCreateCollection` method is the recommended way to avoid "not found" errors entirely. Use `getCollection` only when you specifically need to verify a collection exists.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const client2 = new ChromaClient();
|
|
81
|
+
const embeddingFunction2 = new DefaultEmbeddingFunction();
|
|
82
|
+
|
|
83
|
+
// Preferred: getOrCreateCollection never throws "not found"
|
|
84
|
+
const collection = await client2.getOrCreateCollection({
|
|
85
|
+
name: 'my_collection',
|
|
86
|
+
embeddingFunction: embeddingFunction2,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Check if results exist before accessing
|
|
90
|
+
const results = await collection.query({
|
|
91
|
+
queryTexts: ['search query'],
|
|
92
|
+
nResults: 5,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (results.documents[0] && results.documents[0].length > 0) {
|
|
96
|
+
const firstDoc = results.documents[0][0];
|
|
97
|
+
// Safe to use firstDoc
|
|
98
|
+
} else {
|
|
99
|
+
// No results found
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Validation errors
|
|
104
|
+
|
|
105
|
+
Chroma validates data before operations. Common validation failures include:
|
|
106
|
+
- Document content exceeding 16KB
|
|
107
|
+
- Embedding dimensions not matching the collection
|
|
108
|
+
- Metadata exceeding limits (4KB total, 32 keys max)
|
|
109
|
+
- Invalid collection names
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const client3 = new ChromaClient();
|
|
113
|
+
const embeddingFunction3 = new DefaultEmbeddingFunction();
|
|
114
|
+
|
|
115
|
+
// Validate document size before adding (16KB limit, recommend < 8KB)
|
|
116
|
+
function validateDocument(doc: string): boolean {
|
|
117
|
+
const byteSize = new TextEncoder().encode(doc).length;
|
|
118
|
+
return byteSize <= 16384;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Validate metadata size (4KB limit, 32 keys max)
|
|
122
|
+
function validateMetadata(
|
|
123
|
+
metadata: Record<string, string | number | boolean>
|
|
124
|
+
): boolean {
|
|
125
|
+
const keys = Object.keys(metadata);
|
|
126
|
+
if (keys.length > 32) return false;
|
|
127
|
+
|
|
128
|
+
const jsonSize = new TextEncoder().encode(JSON.stringify(metadata)).length;
|
|
129
|
+
return jsonSize <= 4096;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function safeAdd(
|
|
133
|
+
collectionName: string,
|
|
134
|
+
ids: string[],
|
|
135
|
+
documents: string[],
|
|
136
|
+
metadatas?: Record<string, string | number | boolean>[]
|
|
137
|
+
) {
|
|
138
|
+
// Pre-validate
|
|
139
|
+
for (const doc of documents) {
|
|
140
|
+
if (!validateDocument(doc)) {
|
|
141
|
+
throw new Error(`Document exceeds 16KB limit`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (metadatas) {
|
|
146
|
+
for (const meta of metadatas) {
|
|
147
|
+
if (!validateMetadata(meta)) {
|
|
148
|
+
throw new Error(`Metadata exceeds limits (4KB or 32 keys)`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const collection = await client3.getOrCreateCollection({
|
|
154
|
+
name: collectionName,
|
|
155
|
+
embeddingFunction: embeddingFunction3,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
await collection.add({ ids, documents, metadatas });
|
|
160
|
+
} catch (error) {
|
|
161
|
+
// Handle specific validation errors from server
|
|
162
|
+
if (error instanceof Error) {
|
|
163
|
+
if (error.message.includes('dimension')) {
|
|
164
|
+
throw new Error('Embedding dimensions do not match collection');
|
|
165
|
+
}
|
|
166
|
+
if (error.message.includes('duplicate')) {
|
|
167
|
+
throw new Error('Duplicate IDs in batch');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Batch operation failures
|
|
176
|
+
|
|
177
|
+
When adding or upserting multiple documents, a single invalid document fails the entire batch. Validate data before sending, or implement retry logic for partial failures.
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const client4 = new ChromaClient();
|
|
181
|
+
const embeddingFunction4 = new DefaultEmbeddingFunction();
|
|
182
|
+
|
|
183
|
+
// Process documents in batches to avoid memory issues and partial failures
|
|
184
|
+
async function batchAdd(
|
|
185
|
+
collectionName: string,
|
|
186
|
+
ids: string[],
|
|
187
|
+
documents: string[],
|
|
188
|
+
batchSize = 100
|
|
189
|
+
) {
|
|
190
|
+
const collection = await client4.getOrCreateCollection({
|
|
191
|
+
name: collectionName,
|
|
192
|
+
embeddingFunction: embeddingFunction4,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const failures: { index: number; error: string }[] = [];
|
|
196
|
+
|
|
197
|
+
for (let i = 0; i < ids.length; i += batchSize) {
|
|
198
|
+
const batchIds = ids.slice(i, i + batchSize);
|
|
199
|
+
const batchDocs = documents.slice(i, i + batchSize);
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
await collection.add({
|
|
203
|
+
ids: batchIds,
|
|
204
|
+
documents: batchDocs,
|
|
205
|
+
});
|
|
206
|
+
} catch (error) {
|
|
207
|
+
// Log failure but continue with other batches
|
|
208
|
+
failures.push({
|
|
209
|
+
index: i,
|
|
210
|
+
error: error instanceof Error ? error.message : String(error),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (failures.length > 0) {
|
|
216
|
+
console.error(`${failures.length} batches failed:`, failures);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return { totalBatches: Math.ceil(ids.length / batchSize), failures };
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Defensive patterns summary
|
|
224
|
+
|
|
225
|
+
| Scenario | Recommended approach |
|
|
226
|
+
|----------|---------------------|
|
|
227
|
+
| Collection access | Use `getOrCreateCollection` instead of `getCollection` |
|
|
228
|
+
| Missing data | Check results length before accessing |
|
|
229
|
+
| Connection issues | Implement retry with exponential backoff |
|
|
230
|
+
| Large batches | Validate data size before operations |
|
|
231
|
+
| Local server startup | Verify the server is running before debugging query logic |
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Local Chroma
|
|
3
|
+
description: How to run and use local chroma
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Local Chroma
|
|
7
|
+
|
|
8
|
+
Running Chroma locally is useful for development, testing, and production applications where data privacy or offline operation is important. Local Chroma stores data on disk and runs as a separate process that your application connects to over HTTP.
|
|
9
|
+
|
|
10
|
+
### When to use local vs cloud
|
|
11
|
+
|
|
12
|
+
**Use local Chroma when:**
|
|
13
|
+
- Developing and testing before deploying to production
|
|
14
|
+
- Data must stay on-premises for compliance or privacy reasons
|
|
15
|
+
- You need offline operation without network dependencies
|
|
16
|
+
- Running integration tests in CI/CD pipelines
|
|
17
|
+
|
|
18
|
+
**Use Chroma Cloud when:**
|
|
19
|
+
- You need the Schema() and Search() APIs for advanced indexing
|
|
20
|
+
- You want managed infrastructure without operational overhead
|
|
21
|
+
- You need hybrid search with SPLADE or other cloud-only features
|
|
22
|
+
- Scaling beyond what a single machine can handle
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
For Python, install with pip or uv:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pip install chromadb
|
|
30
|
+
# or
|
|
31
|
+
uv pip install chromadb
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
To start the Chroma server from a Python environment:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
chroma run
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
By default, this starts Chroma on `localhost:8000` and persists data to a local directory.
|
|
41
|
+
|
|
42
|
+
For JavaScript/TypeScript, install with npm:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
npm install chromadb
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
To start the Chroma server:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
npx chroma run
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Connecting to local Chroma
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import chromadb
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Once the server is running, connect using the `ChromaClient` (not `CloudClient`):
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
chroma_client = chromadb.HttpClient(host='localhost', port=8000)
|
|
64
|
+
|
|
65
|
+
# this will automaically use the default embedding function
|
|
66
|
+
collection = chroma_client.get_or_create_collection(name="my_collection")
|
|
67
|
+
|
|
68
|
+
collection.add(
|
|
69
|
+
ids=["id1", "id2"],
|
|
70
|
+
documents=[
|
|
71
|
+
"This is a document about pineapple",
|
|
72
|
+
"This is a document about oranges"
|
|
73
|
+
]
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
results = collection.query(
|
|
77
|
+
query_texts=["This is a query document about hawaii"], # Chroma will embed this for you
|
|
78
|
+
n_results=2 # how many results to return
|
|
79
|
+
)
|
|
80
|
+
print(results)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Persistence
|
|
84
|
+
|
|
85
|
+
Local Chroma persists data to disk automatically. By default, data is stored in `.chroma/` in the current directory. You can specify a different path when starting the server:
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
chroma run --path /path/to/data
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This makes it safe to restart the server without losing your indexed documents.
|
|
92
|
+
|
|
93
|
+
### Further reading
|
|
94
|
+
|
|
95
|
+
For full the full configuration of the chroma server, see: https://docs.trychroma.com/reference/server-env-vars
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Local Chroma
|
|
3
|
+
description: How to run and use local chroma
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Local Chroma
|
|
7
|
+
|
|
8
|
+
Running Chroma locally is useful for development, testing, and production applications where data privacy or offline operation is important. Local Chroma stores data on disk and runs as a separate process that your application connects to over HTTP.
|
|
9
|
+
|
|
10
|
+
### When to use local vs cloud
|
|
11
|
+
|
|
12
|
+
**Use local Chroma when:**
|
|
13
|
+
- Developing and testing before deploying to production
|
|
14
|
+
- Data must stay on-premises for compliance or privacy reasons
|
|
15
|
+
- You need offline operation without network dependencies
|
|
16
|
+
- Running integration tests in CI/CD pipelines
|
|
17
|
+
|
|
18
|
+
**Use Chroma Cloud when:**
|
|
19
|
+
- You need the Schema() and Search() APIs for advanced indexing
|
|
20
|
+
- You want managed infrastructure without operational overhead
|
|
21
|
+
- You need hybrid search with SPLADE or other cloud-only features
|
|
22
|
+
- Scaling beyond what a single machine can handle
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
For Python, install with pip or uv:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pip install chromadb
|
|
30
|
+
# or
|
|
31
|
+
uv pip install chromadb
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
To start the Chroma server from a Python environment:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
chroma run
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
By default, this starts Chroma on `localhost:8000` and persists data to a local directory.
|
|
41
|
+
|
|
42
|
+
For JavaScript/TypeScript, install with npm:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
npm install chromadb
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
To start the Chroma server:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
npx chroma run
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Connecting to local Chroma
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { ChromaClient } from 'chromadb';
|
|
58
|
+
import { DefaultEmbeddingFunction } from '@chroma-core/default-embed';
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Once the server is running, connect using the `ChromaClient` (not `CloudClient`):
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// client with no args uses local chroma instance
|
|
65
|
+
const client = new ChromaClient();
|
|
66
|
+
|
|
67
|
+
const embeddingFunction = new DefaultEmbeddingFunction();
|
|
68
|
+
|
|
69
|
+
const collection = await client.getOrCreateCollection({
|
|
70
|
+
name: 'my_collection',
|
|
71
|
+
embeddingFunction,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await collection.add({
|
|
75
|
+
ids: ['doc1', 'doc2'],
|
|
76
|
+
documents: [
|
|
77
|
+
'Apples are really good red fruit',
|
|
78
|
+
'Red cars tend to get more speeding tickets',
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const results = await collection.query({
|
|
83
|
+
queryTexts: ['I like red apples'],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const firstResult = results.documents[0];
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Persistence
|
|
90
|
+
|
|
91
|
+
Local Chroma persists data to disk automatically. By default, data is stored in `.chroma/` in the current directory. You can specify a different path when starting the server:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
chroma run --path /path/to/data
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
This makes it safe to restart the server without losing your indexed documents.
|
|
98
|
+
|
|
99
|
+
### Further reading
|
|
100
|
+
|
|
101
|
+
For full the full configuration of the chroma server, see: https://docs.trychroma.com/reference/server-env-vars
|