Blueband
Blueband is a vector database on ICP, building from the core of Vectra and its local db principles.
Blueband persists data like a traditional db and saves its embeddings on ICP’s stable memory. This setup can be ideal for use-cases involving small, mostly static datasets where quick comparison is needed.
-
Loading Data into Memory: The index, which contains metadata and vectors, is loaded from the persistent storage (a collection’s canister) into a system’s memory
-
Querying: Once in memory (initialized), the index can be queried to calculate and rank the similarity between saved vectors, and external prompts.
Getting Started
Prerequisites
To use Blueband, deploy a blueband_db_provider canister by adding the prebuilt canister to your dfx.json:
{
"blueband_db_provider": {
"type": "custom",
"candid": "https://github.com/acgodson/blueband-db/releases/download/v0.0.9/blueband-db-backend.did",
"wasm": "https://github.com/acgodson/blueband-db/releases/download/v0.0.9/blueband-db-backend.wasm.gz"
}
}
You can point your backend canister to the blueband_db_provider’s canister to make storage calls from your backend.
ic-use-blueband-db
: is a simple React library for interacting with your db on the frontend. It exports functions to load indexes into the system’s memory, save new items, and compare similarities between saved documents and external prompts using in-memory operations.
Usage
1. Initializing
Connect actor and initialize index:
import {actor} from "./provider_actor_path";
import { useBlueBand } from "ic-use-blueband";
const ReactComponent = () = {
const { initializeIndex} = useBlueband();
const collectionId = "unique collection_id";
cons config = {
collection: collectionId,
api_key: OPENAI_KEY,
/*chunk options*/
}
await initializeIndex(actor, config);
2. Add Items
Add documents to the index:
const { AddItem, Query } = useBlueband();
const title = "Document Title or Url";
const content = "Document content...";
await AddItem(title, content);
3. Query Items
Query the index to find documents similar to a given prompt:
const { Query } = useBlueband();
const results = await Query("query text");
//Results are ranked by similarity scores:
// [
// {
// "title": "Document Title",
// "id": "document_id",
// "score": 0.951178544877223,
// "chunks": 1,
// "sections": [
// /*...*/
// ],
// "tokens": 156
// },
// {
// "title": "Document Title",
// "id": "document_id",
// "score": 0.726565512777365,
// "chunks": 4,
// "sectio ns": [
// /*...*/
// ],
// "tokens": 500
// }
// ]