@ia-ccun/code-agent-cli 0.0.52-beta.6 → 0.0.52-beta.7
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/config/agent/bin/README.md +112 -0
- package/config/agent/bin/fd-win.zip +0 -0
- package/config/agent/bin/rg-win.zip +0 -0
- package/config/agent/extensions/aicode-safety-guard.ts +2 -2
- package/config/agent/extensions/aicode-tips.ts +8 -0
- 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/package.json +1 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# CLI 工具安装指南
|
|
2
|
+
|
|
3
|
+
本目录包含 `fd` 和 `rg`(ripgrep)两个高效文件搜索工具的各平台预编译二进制文件。
|
|
4
|
+
|
|
5
|
+
> **Author**: aicode-cli
|
|
6
|
+
|
|
7
|
+
## 文件清单
|
|
8
|
+
|
|
9
|
+
| 文件名 | 平台 | 版本 |
|
|
10
|
+
|--------|------|------|
|
|
11
|
+
| `fd` | Linux (x86-64 ELF) | 10.3.0 |
|
|
12
|
+
| `rg` | Linux (x86-64 ELF) | 15.1.0 |
|
|
13
|
+
| `fd-win.zip` | Windows (x64) | 10.4.2 |
|
|
14
|
+
| `rg-win.zip` | Windows (x64) | 15.1.0 |
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Linux 用户
|
|
19
|
+
|
|
20
|
+
本目录中的 `fd` 和 `rg` 已是 Linux 可执行文件,无需额外操作,只需赋予执行权限即可使用。
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# 确保有执行权限
|
|
24
|
+
chmod +x fd rg
|
|
25
|
+
|
|
26
|
+
# 验证安装
|
|
27
|
+
./fd --version
|
|
28
|
+
./rg --version
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 安装到系统路径(可选)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
sudo cp fd rg /usr/local/bin/
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
或安装到用户目录:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
mkdir -p ~/.local/bin
|
|
41
|
+
cp fd rg ~/.local/bin/
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
确保 `~/.local/bin` 在 `$PATH` 中。
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Windows 用户
|
|
49
|
+
|
|
50
|
+
需要解压 zip 文件获取 `.exe` 可执行文件
|
|
51
|
+
|
|
52
|
+
### 方法一:文件资源管理器
|
|
53
|
+
|
|
54
|
+
1. 右键 `fd-win.zip` → 解压到当前文件夹
|
|
55
|
+
2. 右键 `rg-win.zip` → 解压到当前文件夹
|
|
56
|
+
3. 将解压出的 `fd.exe` 和 `rg.exe` 复制到你的工具目录
|
|
57
|
+
|
|
58
|
+
### 方法二:PowerShell
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
# 解压
|
|
62
|
+
Expand-Archive fd-win.zip -DestinationPath .
|
|
63
|
+
Expand-Archive rg-win.zip -DestinationPath .
|
|
64
|
+
|
|
65
|
+
# 验证
|
|
66
|
+
.\fd.exe --version
|
|
67
|
+
.\rg.exe --version
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 添加到 PATH(可选)
|
|
71
|
+
|
|
72
|
+
将 `fd.exe` 和 `rg.exe` 放入以下任一位置:
|
|
73
|
+
|
|
74
|
+
- `C:\Users\<用户名>\.aicode-cli\agent\bin\`
|
|
75
|
+
- 或任意已在 `%PATH%` 中的目录
|
|
76
|
+
|
|
77
|
+
**验证:**
|
|
78
|
+
|
|
79
|
+
```powershell
|
|
80
|
+
# 重新打开终端后执行
|
|
81
|
+
fd --version
|
|
82
|
+
rg --version
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## macOS 用户
|
|
88
|
+
|
|
89
|
+
> ⚠️ 本目录 **不提供** macOS 版本二进制文件。
|
|
90
|
+
|
|
91
|
+
请通过 Homebrew 安装:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
brew install fd ripgrep
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 用途说明
|
|
100
|
+
|
|
101
|
+
| 工具 | 用途 | 常用示例 |
|
|
102
|
+
|------|------|----------|
|
|
103
|
+
| `fd` | 快速文件查找 | `fd -e ts "pattern"` |
|
|
104
|
+
| `rg` | 快速文本搜索 | `rg -t ts "pattern"` |
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
详细用法请参阅:
|
|
111
|
+
- fd: https://github.com/sharkdp/fd
|
|
112
|
+
- ripgrep: https://github.com/BurntSushi/ripgrep
|
|
Binary file
|
|
Binary file
|
|
@@ -266,10 +266,10 @@ async function confirmOrBlock(
|
|
|
266
266
|
finish({ allow: true, scope: "permanent" });
|
|
267
267
|
break;
|
|
268
268
|
default:
|
|
269
|
-
finish({ block: true, reason: "Blocked by safety-guard extension" });
|
|
269
|
+
finish({ block: true, reason: "Blocked by aicode-safety-guard extension" });
|
|
270
270
|
break;
|
|
271
271
|
}
|
|
272
|
-
}).catch(() => finish({ block: true, reason: "Blocked by safety-guard extension" }));
|
|
272
|
+
}).catch(() => finish({ block: true, reason: "Blocked by aicode-safety-guard extension" }));
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
|
|
@@ -98,6 +98,14 @@ const AICODE_TIPS = [
|
|
|
98
98
|
"/btw 并行侧边对话,可在不中断主流程的情况下进行临时讨论或查询 ",
|
|
99
99
|
"/rewind 回退到任意工具执行前的状态,支持快照恢复和撤销重做 ",
|
|
100
100
|
"/mcp 连接现有的 MCP 服务器 (如 xx 平台、企业微信等等),扩展 AI 能力支持多种外部工具和服务 ",
|
|
101
|
+
// 新增扩展命令提示
|
|
102
|
+
"/cd 路径 切换会话工作目录,快速跳转不同项目",
|
|
103
|
+
"/grill-me 启动设计访谈,系统收集需求并生成决策文档",
|
|
104
|
+
"/ponytail 开启极简模式,强制 AI 用最少代码解决问题",
|
|
105
|
+
"💡 多步骤任务会自动显示待办进度条,实时跟踪完成情况",
|
|
106
|
+
"💡 需要理解陌生代码库时说'帮我解读这个项目',自动构建知识图谱",
|
|
107
|
+
"💡 autoresearch:自动实验循环,持续优化参数直到收敛",
|
|
108
|
+
"🛡️ 安全围栏已默认启用,自动拦截危险操作(rm -rf、git reset --hard 等)",
|
|
101
109
|
// 新增扩展功能提示
|
|
102
110
|
"Alt+/ 或 Ctrl+Alt+W 快速切换到 BTW 侧边对话窗口",
|
|
103
111
|
"BTW 侧边对话:独立上下文,不影响主会话,适合临时查询和讨论",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chroma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: chroma-local
|
|
3
|
+
description: Use when the user needs self-hosted or local Chroma for semantic search, including `ChromaClient`, `HttpClient`, or Python `EphemeralClient`, local persistence, Docker or `chroma run`, or OSS Chroma without Chroma Cloud features.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
|
|
8
|
+
Determine these before writing code. Prefer discovering them from the repo and the user request. Ask only when the choice materially changes the implementation.
|
|
9
|
+
|
|
10
|
+
1. **Runtime shape**
|
|
11
|
+
- Are they connecting to a running local server, embedding Chroma into tests, or setting up local development from scratch?
|
|
12
|
+
- Decide whether they need `chroma run`, a Docker or service command, `HttpClient` or `ChromaClient`, or Python `EphemeralClient`.
|
|
13
|
+
|
|
14
|
+
2. **Persistence**
|
|
15
|
+
- Persistent local data: choose an intentional data path.
|
|
16
|
+
- Disposable test data: use defaults or a temp directory.
|
|
17
|
+
|
|
18
|
+
3. **Embedding model**
|
|
19
|
+
- Reuse the app's existing embedding provider when possible.
|
|
20
|
+
- Otherwise default to `@chroma-core/default-embed` in TypeScript or the standard local default in Python.
|
|
21
|
+
- If the user explicitly wants OpenAI embeddings in TypeScript, install and use `@chroma-core/openai`.
|
|
22
|
+
|
|
23
|
+
4. **Indexed data shape**
|
|
24
|
+
- Determine what is being indexed, how it should be chunked, and what metadata is needed for filtering and updates.
|
|
25
|
+
|
|
26
|
+
## Routing
|
|
27
|
+
|
|
28
|
+
- **Existing local server**
|
|
29
|
+
- Confirm host and port before changing client code.
|
|
30
|
+
- Validate the server is reachable before assuming collections are missing.
|
|
31
|
+
|
|
32
|
+
- **Fresh local development**
|
|
33
|
+
- Add a local startup path such as `chroma run` or the repo's existing Docker or service command.
|
|
34
|
+
- Default to `localhost:8000` unless the repo already uses another address.
|
|
35
|
+
|
|
36
|
+
- **Python tests or disposable local workflows**
|
|
37
|
+
- Prefer `EphemeralClient` when persistence is unnecessary.
|
|
38
|
+
- Call out that data is lost when the process exits.
|
|
39
|
+
|
|
40
|
+
- **Persistent local development**
|
|
41
|
+
- Use a stable data path and make persistence explicit in code or config.
|
|
42
|
+
- Do not silently switch between ephemeral and persistent modes.
|
|
43
|
+
|
|
44
|
+
- **Search integration work**
|
|
45
|
+
- Use `getOrCreateCollection()` in TypeScript or `get_or_create_collection()` in Python.
|
|
46
|
+
- Design document IDs and metadata so upserts and deletes are straightforward.
|
|
47
|
+
- Batch writes when syncing large datasets.
|
|
48
|
+
|
|
49
|
+
## Ask vs proceed
|
|
50
|
+
|
|
51
|
+
**Ask first:**
|
|
52
|
+
- Embedding model choice (cost and quality implications)
|
|
53
|
+
- Whether they need persistent local data
|
|
54
|
+
- How they are starting the local server
|
|
55
|
+
- Multi-tenant data isolation strategy
|
|
56
|
+
|
|
57
|
+
**Proceed with sensible defaults:**
|
|
58
|
+
- Use `getOrCreateCollection()` (TypeScript) / `get_or_create_collection()` (Python)
|
|
59
|
+
- Use cosine similarity (most common)
|
|
60
|
+
- Chunk size under 8KB
|
|
61
|
+
- Store source IDs in metadata for updates/deletes
|
|
62
|
+
- Use a local server on `localhost:8000` unless the repo already configures another address or is using Python `EphemeralClient`
|
|
63
|
+
|
|
64
|
+
## What to validate
|
|
65
|
+
|
|
66
|
+
- Correct client import (`ChromaClient`, `HttpClient`, or `Client`)
|
|
67
|
+
- Embedding function package is installed (TypeScript)
|
|
68
|
+
- Local server is reachable before assuming collections are missing
|
|
69
|
+
- Local path and persistence mode are intentional
|
|
70
|
+
|
|
71
|
+
## Implementation notes
|
|
72
|
+
|
|
73
|
+
- Local Chroma is the right default for development, tests, and self-hosted deployments.
|
|
74
|
+
- OSS Chroma does not include Chroma Cloud-only features such as `Schema()` and `Search()`.
|
|
75
|
+
- If the user asks for hybrid dense and sparse retrieval, treat that as a likely Chroma Cloud requirement unless the repo already implements an OSS workaround.
|
|
76
|
+
- For open source Chroma, dense retrieval with a single embedding function is the normal baseline.
|
|
77
|
+
|
|
78
|
+
## Minimal patterns
|
|
79
|
+
|
|
80
|
+
Start a local Chroma server when the repo needs one:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
chroma run
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Default address: `localhost:8000`.
|
|
87
|
+
|
|
88
|
+
TypeScript local client:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { ChromaClient } from 'chromadb';
|
|
92
|
+
import { DefaultEmbeddingFunction } from '@chroma-core/default-embed';
|
|
93
|
+
|
|
94
|
+
const client = new ChromaClient();
|
|
95
|
+
|
|
96
|
+
const embeddingFunction = new DefaultEmbeddingFunction();
|
|
97
|
+
const collection = await client.getOrCreateCollection({
|
|
98
|
+
name: 'my_collection',
|
|
99
|
+
embeddingFunction,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Add documents
|
|
103
|
+
await collection.add({
|
|
104
|
+
ids: ['doc1', 'doc2'],
|
|
105
|
+
documents: ['First document text', 'Second document text'],
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Query
|
|
109
|
+
const results = await collection.query({
|
|
110
|
+
queryTexts: ['search query'],
|
|
111
|
+
nResults: 5,
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Python local client:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import chromadb
|
|
119
|
+
|
|
120
|
+
client = chromadb.HttpClient(host="localhost", port=8000)
|
|
121
|
+
|
|
122
|
+
collection = client.get_or_create_collection(name="my_collection")
|
|
123
|
+
|
|
124
|
+
# Add documents
|
|
125
|
+
collection.add(
|
|
126
|
+
ids=["doc1", "doc2"] ,
|
|
127
|
+
documents=["First document text", "Second document text"],
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# Query
|
|
131
|
+
results = collection.query(
|
|
132
|
+
query_texts=["search query"],
|
|
133
|
+
n_results=5,
|
|
134
|
+
)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Learn More
|
|
138
|
+
|
|
139
|
+
Fetch Chroma's `llms.txt` only when you need API or product details that are not already in the repo or this skill: https://docs.trychroma.com/llms.txt
|
|
140
|
+
|
|
141
|
+
## Available Topics
|
|
142
|
+
|
|
143
|
+
### Typescript
|
|
144
|
+
|
|
145
|
+
- [Chroma Regex Filtering](./regex/typescript.md) - Learn how to use regex filters in Chroma queries
|
|
146
|
+
- [Query and Get](./querying/typescript.md) - Query and Get Data from Chroma Collections
|
|
147
|
+
- [Metadata](./metadata/typescript.md) - Store and query metadata, including filters and array values
|
|
148
|
+
- [Updating and Deleting](./updating-deleting/typescript.md) - Update existing documents and delete data from collections
|
|
149
|
+
- [Error Handling](./error-handling/typescript.md) - Handling errors and failures when working with Chroma
|
|
150
|
+
- [Local Chroma](./local-chroma/typescript.md) - How to run and use local chroma
|
|
151
|
+
|
|
152
|
+
### Python
|
|
153
|
+
|
|
154
|
+
- [Chroma Regex Filtering](./regex/python.md) - Learn how to use regex filters in Chroma queries
|
|
155
|
+
- [Query and Get](./querying/python.md) - Query and Get Data from Chroma Collections
|
|
156
|
+
- [Metadata](./metadata/python.md) - Store and query metadata, including filters and array values
|
|
157
|
+
- [Updating and Deleting](./updating-deleting/python.md) - Update existing documents and delete data from collections
|
|
158
|
+
- [Error Handling](./error-handling/python.md) - Handling errors and failures when working with Chroma
|
|
159
|
+
- [Local Chroma](./local-chroma/python.md) - How to run and use local chroma
|
|
160
|
+
|
|
161
|
+
## General
|
|
162
|
+
|
|
163
|
+
- [Data Model](./data-model.md) - An overview of how Chroma stores data
|
|
164
|
+
- [Integrating Chroma into an existing system](./understanding-a-codebase.md) - Guidance for adding Chroma search to an existing application
|
|
165
|
+
- [Chroma CLI](./cli.md) - Starting and managing a local open source Chroma server from the CLI
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Chroma CLI
|
|
3
|
+
description: Starting and managing a local open source Chroma server from the CLI
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Chroma CLI
|
|
7
|
+
|
|
8
|
+
The Chroma CLI can also be used for local open source Chroma workflows. This topic focuses on starting and managing a local server, not Chroma Cloud account setup.
|
|
9
|
+
|
|
10
|
+
### Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install chromadb
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Start a local server
|
|
17
|
+
|
|
18
|
+
Run Chroma locally on the default address:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
chroma run
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
This starts a server on `localhost:8000`.
|
|
25
|
+
|
|
26
|
+
### Choose a persistent data directory
|
|
27
|
+
|
|
28
|
+
Store local data in a specific path instead of the default working directory:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
chroma run --path ./chroma-data
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Change the port
|
|
35
|
+
|
|
36
|
+
If another process already uses port `8000`, pick another one:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
chroma run --port 8001
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Update your client code to match the chosen host and port.
|
|
43
|
+
|
|
44
|
+
### Local workflow tips
|
|
45
|
+
|
|
46
|
+
- Use a dedicated data directory per environment so dev and test data do not mix.
|
|
47
|
+
- In tests, use disposable directories or clear collections between runs.
|
|
48
|
+
- Check that the server is running before debugging client-side collection errors.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Data Model
|
|
3
|
+
description: An overview of how Chroma stores data
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Data Model
|
|
7
|
+
|
|
8
|
+
Use this reference when designing collection layout, chunking, IDs, metadata, and filtering for Chroma.
|
|
9
|
+
|
|
10
|
+
### Core concepts
|
|
11
|
+
|
|
12
|
+
**Collections** are the top-level containers, similar to tables in a relational database. Each collection has its own embedding configuration and indexes.
|
|
13
|
+
|
|
14
|
+
**Documents** are the searchable units within a collection. Each document has:
|
|
15
|
+
- **ID** - A unique string identifier
|
|
16
|
+
- **Content** - The text that gets embedded and searched
|
|
17
|
+
- **Embedding** - The vector representation
|
|
18
|
+
- **Metadata** - Key-value pairs for filtering
|
|
19
|
+
|
|
20
|
+
## Chunking
|
|
21
|
+
|
|
22
|
+
Most real-world data is too large to fit in a single document. Chunking splits content into searchable pieces.
|
|
23
|
+
|
|
24
|
+
### Chunking strategy
|
|
25
|
+
|
|
26
|
+
**Recommended chunk size:** Keep chunks comfortably below product limits and small enough to preserve search precision and context. Generally, 8KB or less is a good default starting point.
|
|
27
|
+
|
|
28
|
+
**Good chunking preserves meaning:**
|
|
29
|
+
- Split at natural boundaries (paragraphs, sentences, sections)
|
|
30
|
+
- Don't cut mid-sentence or mid-word
|
|
31
|
+
- Include enough context for the chunk to be meaningful on its own
|
|
32
|
+
|
|
33
|
+
**Determine from the repo or ask if ambiguous:**
|
|
34
|
+
- What type of content are they indexing?
|
|
35
|
+
- Are there natural boundaries (chapters, sections, records)?
|
|
36
|
+
- How much context does a search result need to be useful?
|
|
37
|
+
|
|
38
|
+
### Tracking chunks with metadata
|
|
39
|
+
|
|
40
|
+
When a single source document becomes multiple chunks, use metadata to track the relationship:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
{
|
|
44
|
+
"source_id": "post-123", // ID in the primary database
|
|
45
|
+
"source_type": "blog_post", // Type of content
|
|
46
|
+
"chunk_index": 0, // Position in sequence
|
|
47
|
+
"total_chunks": 3 // Total chunks from this source
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This approach is better than encoding information in the document ID because:
|
|
52
|
+
- IDs can be simple UUIDs
|
|
53
|
+
- Metadata is filterable
|
|
54
|
+
- Updates and deletes are easier (filter by `source_id`)
|
|
55
|
+
|
|
56
|
+
## Collection organization
|
|
57
|
+
|
|
58
|
+
For multi-tenant applications, separate collections per tenant are a strong default when isolation, deletion, and search quality matter more than minimizing collection count.
|
|
59
|
+
|
|
60
|
+
**Why this works better:**
|
|
61
|
+
- Nearest neighbor search is more accurate with fewer candidates
|
|
62
|
+
- Lower latency with smaller collections
|
|
63
|
+
- Natural isolation between tenants
|
|
64
|
+
- Easy to delete all tenant data by dropping the collection
|
|
65
|
+
|
|
66
|
+
**Example:** A knowledge base SaaS might have collections like `kb_customer_123`, `kb_customer_456`, etc.
|
|
67
|
+
|
|
68
|
+
**Determine from the repo or ask if ambiguous:** What's the smallest logical unit of data isolation in their application?
|
|
69
|
+
|
|
70
|
+
## Filtering
|
|
71
|
+
|
|
72
|
+
Metadata filtering reduces the candidate set before vector search runs, making queries faster and more precise.
|
|
73
|
+
|
|
74
|
+
### Filter operators
|
|
75
|
+
|
|
76
|
+
| Operator | Description | Types |
|
|
77
|
+
|----------|-------------|-------|
|
|
78
|
+
| `$eq` | Equal (default) | string, int, bool |
|
|
79
|
+
| `$ne` | Not equal | string, int, bool |
|
|
80
|
+
| `$gt`, `$gte` | Greater than (or equal) | int |
|
|
81
|
+
| `$lt`, `$lte` | Less than (or equal) | int |
|
|
82
|
+
| `$in` | In list | string, int |
|
|
83
|
+
| `$nin` | Not in list | string, int |
|
|
84
|
+
| `$and`, `$or` | Logical combinators | filter arrays |
|
|
85
|
+
| `$contains`, `$not_contains` | Check within arrays | arrays of string, int, bool |
|
|
86
|
+
|
|
87
|
+
### Document content filtering
|
|
88
|
+
|
|
89
|
+
Beyond metadata, you can filter on the document text itself using `where_document`:
|
|
90
|
+
- `$contains` - Full-text substring search
|
|
91
|
+
- `$regex` - Regular expression matching
|
|
92
|
+
|
|
93
|
+
## Dense vs sparse vectors
|
|
94
|
+
|
|
95
|
+
**Dense vectors** (default) are produced by neural embedding models. They capture semantic meaning, so "car" and "automobile" will be similar.
|
|
96
|
+
|
|
97
|
+
**Sparse vectors** (BM25, SPLADE) are high-dimensional but mostly zeros. They excel at exact keyword matching.
|
|
98
|
+
|
|
99
|
+
**Hybrid search** combines both, often outperforming either alone. Chroma Cloud supports hybrid search through the Schema and Search APIs.
|
|
100
|
+
|
|
101
|
+
### Important note
|
|
102
|
+
|
|
103
|
+
When creating collections, `get_or_create_collection()` accepts either an `embedding_function` OR a `schema`, but not both. Use Schema when you need multiple indexes or sparse embeddings.
|
|
@@ -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 |
|