2025-10-25 20:28:40 -03:00
# VectorDB Integration
2025-10-25 15:59:06 -03:00
2025-10-25 20:28:40 -03:00
GeneralBots uses **VectorDB** as the vector database for storing and searching embeddings. The Rust client for the configured VectorDB is used to communicate with the service.
2025-10-25 15:59:06 -03:00
## Configuration
The connection is configured via environment variables:
```env
2025-10-25 20:28:40 -03:00
VECTORDB_URL=http://localhost:6333
VECTORDB_API_KEY=your-api-key # optional
2025-10-25 15:59:06 -03:00
```
2025-10-25 20:28:40 -03:00
These values are read at startup and passed to the `VectorDBClient` .
2025-10-25 15:59:06 -03:00
## Collection Mapping
2025-10-25 20:28:40 -03:00
Each `.gbkb` collection maps to a VectorDB collection with the same name. For example, a knowledge base named `company-policies` becomes a VectorDB collection `company-policies` .
2025-10-25 15:59:06 -03:00
## Operations
- **Insert** – Performed during indexing (see Chapter 03).
- **Search** – Executed by the `FIND` keyword, which sends a query vector and retrieves the top‑ k nearest neighbors.
- **Delete/Update** – When a document is removed or re‑ indexed, the corresponding vectors are deleted and replaced.
## Performance Tips
- Keep the number of vectors per collection reasonable (tens of thousands) for optimal latency.
2025-10-25 20:28:40 -03:00
- Adjust VectorDB’ s `hnsw` parameters in `VectorDBClient::new` if you need higher recall.
2025-10-25 15:59:06 -03:00
- Use the `FILTER` option to restrict searches by metadata (e.g., source file).
## Example `FIND` Usage
```basic
2025-11-21 23:23:53 -03:00
USE_KB "company-policies"
2025-10-25 15:59:06 -03:00
FIND "vacation policy" INTO RESULT
TALK RESULT
```
The keyword internally:
1. Generates an embedding for the query string.
2025-10-25 20:28:40 -03:00
2. Calls VectorDB’ s `search` API.
2025-10-25 15:59:06 -03:00
3. Returns the most relevant chunk as `RESULT` .