Skip to content
Docs · Data

Vector DB

Your app's documents, searched by meaning, for semantic search and RAG. Send text and Harakumo embeds it and keeps it: every match comes back with its text. Filter by metadata, keep each end user apart with a namespace, and open a collection to your agents' visitor chat.

View as Markdown
All topics
On this page

Each collection is its own vector index. The default is 768 dimensions — what Harakumo's default embedding model (bge-base, English) produces, so text you send fits as-is. Choose 384 (bge-small) or 1,024 (bge-large) to match those models, or 1,536 for vectors you make elsewhere; larger is refused.

Vector DB holds your app's documents, chunked and searched by meaning, with their text returned. To remember facts about one end user (their preferences, their conversations), use Memory, which always takes a userId.

embed("query")nearest matches#42 0.91#7 0.88#19 0.84semantic search over your embeddings

In plain words

Search by meaning instead of exact words. You add your texts, and it finds the ones closest in meaning to what someone asks.

For example: Someone types "how do I get my money back" into a help center and finds the article called "Refunds".

Embed, upsert, query

  • The text you send is kept with the vector (with values too) and comes back as text on every match and from fetch. A vector written before text was kept has none: upsert it again to add it. It comes back with returnMetadata: "all", the default, so with topK 50 or fewer.
  • A text is at most 2,000 characters (about what the embedding model reads). Longer is a 400 input_too_long naming the field (vectors[3].text), never cut: split it into chunks of about 1,000-1,500 characters.
  • Metadata plus the text is at most 10,240 bytes per vector (400 metadata_too_large). Metadata keys that start with _hk_ are Harakumo's own and are refused.
  • New vectors become searchable in about a minute. GET /api/vectors/:id answers all_writes_searchable: true once every write so far can be found.
SDK
const { collection } = await hk.vectors.create(project.id, {
  name: 'docs', dimensions: 768, metric: 'cosine',
  metadataIndexes: [{ propertyName: 'lang', indexType: 'string' }],
});

// Send text (at most 2,000 characters each; split longer documents into chunks
// with ids like doc42#0, doc42#1). Harakumo embeds it (metered on AI credits) and keeps it.
await hk.vectors.upsert(collection.id, [
  { id: 'doc-1#0', text: 'Peaches are in season in July.', metadata: { lang: 'en' } },
  { id: 'doc-2#0', text: 'Mangoes ripen best at room temperature.', metadata: { lang: 'en' } },
]);

const { matches } = await hk.vectors.query(collection.id, {
  text: 'when can I buy peaches?', topK: 3, filter: { lang: 'en' },
});
// matches: [{ id: 'doc-1#0', score: 0.83, text: 'Peaches are in season in July.', metadata: { lang: 'en' } }, …]

Namespaces: one per end user

  • Give each vector a namespace: your end user's id (userId is the same field, the name Memory uses; send one, or both the same). A query that names it sees only that user's vectors. A namespace written to is 1-64 characters: letters, digits and . _ - : @ + =, so an id or an email fits as-is. An older namespace with other characters (a space, a slash) can still be searched and fetched from, but no longer written to: upsert those vectors again under a new one.
  • Leaving the namespace out of a query searches every namespace in the collection. Always pass it from your server when a search is about one user.
  • Give every vector an id that is unique in the whole collection, not only in its namespace: fetch and delete take ids without a namespace, so two vectors sharing an id under two namespaces cannot be told apart. Prefix ids with the user's id (u42:note-1), which also makes forgetting a user a delete by those ids. Up to 50,000 namespaces per collection.

Filters

  • A filter is { field: value } or { field: { $eq | $ne | $in | $nin | $lt | $lte | $gt | $gte: … } }; several fields in one filter mean AND. There is no $or or $exists: those are a 400 filter_operator_unsupported that names the operator.
  • Filters work on metadata fields made filterable with metadataIndexes, at create time or later with PATCH /api/vectors/:id { metadataIndexes: [{ propertyName, indexType }] } (string, number or boolean; at most 10 per collection, never removed). Only vectors written after a field is made filterable can be filtered on it, so re-upsert existing ones. A filter on any other field is a 400 field_not_filterable that says so.

Read, delete and change

  • POST /api/vectors/:id/fetch { ids, includeValues? } reads up to 100 vectors back by id: text, metadata and namespace (values when asked), and notFound.
  • POST /api/vectors/:id { action: "delete", ids: [...] } deletes up to 1,000 ids per request (each at most 64 bytes, repeats dropped); deleted counts the ids sent, found or not, and they leave search in about a minute. The SDK's deleteIds sends any number, 1,000 at a time.
  • PATCH /api/vectors/:id { visitorChat?, metadataIndexes? } changes a collection. DELETE /api/vectors/:id deletes it and every vector in it.

Visitor chat

  • An agent answering your app's visitors (visitor chat) may search a collection only once you open it: visitorChat: true on create, or PATCH /api/vectors/:id { visitorChat: true }. Collections start closed. Open one only if anything in it may be shown to anyone on your page.
  • A visitor's chat lists only the open collections, and is refused any other collection (describe, query or fetch) with 403 not_open_to_visitors. It searches by text across the whole collection, every namespace included, with at most 10 matches: open only a collection whose every vector may be shown to anyone. With no collection open, the agent's visitor runs have no document tools, and turning chat on says so (chat_note). Memory is never open to visitor chat.

Limits

  • Upsert up to 1,000 vectors per request (100 when sending text).
  • topK up to 100, or 50 when returning full metadata (and the text) or values.
  • Upserts are applied in the background: new vectors become searchable in about a minute, and the upsert answer says so. GET /api/vectors/:id reports the index's own count, which trails new writes by as much; the list shows the count as last read.
  • Collections per plan: 1 hobby, 1 indie, 10 pro, 25 team, 100 scale. Vectors per collection: 10,000 hobby, 20,000 indie, 1,000,000 pro, 1,000,000 team, 1,000,000 scale; a write that would pass it answers 402 plan_limit and writes nothing. Near the limit every vector sent counts as new until the index has processed it, even one that replaces an existing id, and a delete makes room once the index has processed it.
  • Keys: a key limited to the project works for everything here. A read-only key can query (by text too, charged to AI credits) and fetch, but not upsert, change or delete.

Errors

  • Creating a collection when its index cannot be made answers 503 with Retry-After and keeps nothing. Deleting one when its index cannot be deleted answers 503 (or 502) and deletes nothing, so you can try again.
CodeStatusWhen
input_too_long400A text is over 2,000 characters. param names it; split it into chunks.
metadata_too_large400Metadata plus text is over 10,240 bytes.
conflicting_param400namespace and userId were both sent and differ.
filter_operator_unsupported400The filter uses $or, $exists or another operator the index does not have.
field_not_filterable400The filter names a field that is not filterable on this collection.
invalid_request400Anything else malformed, with param when one field is at fault; also an 11th filterable field.
ai_gateway_off403Text was sent while the AI Gateway is switched off; send vectors you computed instead.
embedding_failed502The embedding model failed; nothing was charged or written. Try again.
not_open_to_visitors403A visitor's chat reached a collection not open to it.
plan_limit402The collection is at its plan's vectors per collection.
rate_limited429The index (or the embedding model) is busy, or the data allowance is used up; retry after Retry-After.
index_unavailable501 / 502The collection has no index behind it (501: delete it and create a new one), or its index is busy (502 with Retry-After: try again).
may_have_landed503The index did not confirm an upsert; sending the same vectors again is safe.
count_unavailable503A collection whose count was never read could not be counted for the plan's cap; retry.
maintenance503During a platform move text is not embedded; a query by vector still works.

Reference

SDK
const { embeddings } = await hk.ai.embed(['fresh mango', 'ripe banana'], 'bge-base');   // 768 dims
await hk.vectors.upsert(collectionId, [{ id: 'u42:a', values: embeddings[0], text: 'fresh mango', metadata: { title: 'Mango' }, userId: 'u42' }]);
const { matches } = await hk.vectors.query(collectionId, { vector: embeddings[1], topK: 5, userId: 'u42' });
const { vectors, notFound } = await hk.vectors.fetch(collectionId, ['u42:a']);
await hk.vectors.update(collectionId, { visitorChat: true, metadataIndexes: [{ propertyName: 'title', indexType: 'string' }] });