Skip to main content

HydraDB Agent Integration Guide

This document is a self-contained reference designed for AI coding agents. It covers everything needed to understand, install, configure, and integrate HydraDB into any project — from zero prior knowledge to production-ready usage.

TL;DR: Critical endpoints

  1. POST /databases (client.databases.create()): Provision an isolated database workspace.
  2. GET /databases/status (client.databases.status()): Poll until infra.ready_for_ingestion is true.
  3. POST /context/ingest (client.context.ingest()): Ingest documents, app records, or memories under type="knowledge" or type="memory".
  4. GET /context/status (client.context.status()): Poll status using ids until indexing_status is completed or graph_creation.
  5. POST /query (client.query()): Retrieve context via type: "knowledge", "memory", or "all".

1. Critical rules for LLMs

API versioning and auth

  • Base URL: https://api.hydradb.com
  • Raw HTTP calls must include:
    • Authorization: Bearer <api_key>
    • API-Version: 2
  • Official SDKs set API-Version: 2 automatically.
  • Use HYDRA_DB_API_KEY as the environment variable in examples.

Response envelope

Core raw HTTP responses (/databases, /context/*, and /query) are wrapped:
  • Parse core raw HTTP payloads from data.
  • The SDKs return the full envelope object; read the payload from its data field (e.g. response.data). On failure they raise a typed exception rather than returning an envelope with error set.
  • Log meta.request_id for failed requests.
  • meta may also carry an optional deprecation list (with a Deprecation: true response header) when a request uses a legacy /tenants route or a deprecated field (tenant_id/sub_tenant_id, or sub_tenant_ids on /query). Each entry has deprecated, deprecated_field, preferred_field, message, and deprecated_since. It is a non-breaking nudge. The status code is unchanged. Prefer the /databases routes and database/collection/collections fields to avoid it. Treat meta as an open object: ignore keys you do not recognize.
  • Exception: webhook management endpoints (/webhooks/indexing*) return their documented response object directly, without the { success, data, error, meta } envelope.

Core endpoints

Async lifecycle

Two operations are asynchronous:
  1. Database creation: after POST /databases, poll GET /databases/status until infrastructure is ready.
  2. Ingestion: after POST /context/ingest, poll GET /context/status until the content is searchable or fully complete.
Searchable status:
  • graph_creation: searchable, graph may still be incomplete.
  • completed: fully indexed and graphed.
Failure status:
  • Docs use errored; OpenAPI also exposes failed in one enum. Treat both as terminal failures.

Search parameter naming

The canonical request field for POST /query is type:
  • type: "knowledge"
  • type: "memory"
  • type: "all"
Use the same type enum across context lifecycle APIs and search. Search additionally accepts "all" to query knowledge and memories together.

Metadata naming

  • tenant_metadata: schema-aligned, declared at database creation, fast filter path.
  • additional_metadata: canonical free-form per-document metadata.
  • document_metadata: multipart field carrying per-document metadata for file uploads; use additional_metadata inside each item for free-form metadata.
  • metadata_filters top-level keys match tenant_metadata.
  • metadata_filters.additional_metadata scopes free-form metadata.

Do not mix scopes accidentally

  • database (formerly tenant_id) is the hard isolation boundary.
  • collection (formerly sub_tenant_id) is a logical partition inside a database, typically user/workspace/team.
  • Use the same collection on writes and reads. Data written under one collection should not be expected to appear from another.
  • Do not use metadata_filters as a substitute for collection.

2. Core primitives

Databases and collections

A database is an isolated workspace. A collection partitions data inside a database. Recommended patterns:

Knowledge

Knowledge is shared context: documents, PDFs, Markdown, CSVs, Slack threads, Notion pages, Gmail threads, tickets, webpages, etc.
  • Ingest with POST /context/ingest, type=knowledge.
  • Search with POST /query, type: "knowledge".
  • Use for content that should be reusable across users.
  • Mutability is explicit: re-ingest with the same ID and upsert: true, or delete.

Memories

Memories are user/workspace/session-scoped context: preferences, conversation history, behavioral signals, decisions, inferred traits.
  • Ingest with POST /context/ingest, type=memory.
  • Search with POST /query, type: "memory" or type: "all".
  • Always pass the same collection used at ingestion.
  • Use infer: true when the input is raw signal and HydraDB should extract the durable preference/fact.
  • Use infer: false when the memory is already structured and should be stored verbatim.

Query

POST /query is the single retrieval endpoint. It can search:
  • Knowledge only: type: "knowledge"
  • Memories only: type: "memory"
  • Both stores together: type: "all"
It supports:
  • query_by: "hybrid" for semantic + BM25 retrieval.
  • query_by: "text" for BM25 keyword/phrase search.
  • mode: "fast" for low latency.
  • mode: "thinking" for query expansion, reranking, richer graph traversal, and forceful-relation expansion.

Context graph

HydraDB builds a graph of entity/relation triplets from ingested content. When graph_context: true (default), search can return:
  • graph_context.query_paths
  • graph_context.chunk_relations
  • graph_context.chunk_id_to_group_ids
Graph context augments retrieval; chunks remain the primary search output.

Forceful relations

At ingestion, sources can declare explicit relations:
At search time, set or rely on default query_forceful_relations: true with mode: "thinking" to pull related chunks into additional_context. Rules:
  • Forceful relation expansion only takes effect in mode: "thinking".
  • Use ids.
  • Relations are store-local: memory-to-memory or knowledge-to-knowledge. Cross-store relation lookups may not surface anything.

3. Installation and client setup

Python SDK

Async client:

TypeScript SDK

SDK naming:
  • Python methods and fields: snake_case, e.g. client.databases.collections(), database, collection, page_size, query_by.
  • TypeScript methods and fields: camelCase, e.g. client.databases.collections(), database, collection, pageSize, queryBy.
  • Both SDKs return a { success, data, error, meta } envelope; the payload is under .data (e.g. response.data.infra, response.data.statuses, response.data.results).
  • Values that are passed as JSON strings (memories, app_knowledge, document_metadata) keep snake_case keys inside the stringified payload in both SDKs, since that is raw wire data.

4. Minimal end-to-end flow

Python

TypeScript


5. Databases API

Create database

POST /databases · client.databases.create()
Notes:
  • Database creation is async.
  • database should be stable; docs recommend lowercase letters, numbers, and underscores for portability.
  • database_metadata_schema is effectively planned up front. If you need to change filterable metadata fields, expect to create a new database or re-ingest under a new schema.
  • POST /databases may return 409 DATABASE_ALREADY_EXISTS for duplicate database IDs and 403 FORBIDDEN when the API key or plan cannot create more databases.

Check readiness

GET /databases/status?database=... · client.databases.status() Ready when infrastructure reports usable status. Current docs show infra.ready_for_ingestion; SDK examples also check:
  • infra.scheduler_status
  • infra.graph_status
  • infra.vectorstore_status.knowledge
  • infra.vectorstore_status.memories
Use SDK autocomplete/returned object shape for the exact field spelling.

Other database endpoints


6. Source ingestion

POST /context/ingest is the unified write endpoint for knowledge and memories.

Common form fields

Knowledge from files

Use for PDFs, DOCX, Markdown, CSV, TXT, and other files HydraDB should parse.
document_metadata item fields:

Knowledge from app sources

Use app_knowledge when your connector already extracted text from Slack, Gmail, Jira, Linear, Zendesk, Notion, Confluence, Salesforce, webpages, etc.
Recommended app-source fields: App-source object kinds in OpenAPI include:
  • email
  • message
  • ticket
  • knowledge_base
  • comment
  • custom
Modern docs show both a generic content shape and a richer app shape with kind, provider, external_id, fields, attachments, comments, and relations. Use the richer shape when building app-aware search; at minimum provide stable IDs, content, source type, metadata, and relations.

Memories

Use type="memory" and a JSON-stringified memories array.
Memory item fields:

7. Context status and lifecycle

Poll indexing

GET /context/status · client.context.status() Parameters:
  • database required
  • ids required array
  • collection optional, but should match ingestion scope
Status meanings from docs: Pattern:

Webhooks instead of polling

Use /webhooks/indexing to receive terminal indexing events. Endpoints: Supported event:
  • indexing.status_changed
Payload shape:
Headers:
  • X-HydraDB-Delivery-ID
  • X-HydraDB-Event
  • X-HydraDB-Signature when a signing secret is configured
Rules:
  • Webhook URL must be public HTTPS; localhost/private networks are blocked.
  • Store delivery_id to deduplicate retries.
  • If using signing_secret, verify X-HydraDB-Signature.

8. Query API

POST /query · client.query()

Request fields that matter

Search examples

Knowledge RAG:
Personalized answer using knowledge and memories:
Exact phrase:
Metadata-scoped search:

Search response

The successful data object / SDK return is a RetrievalResult:
Use chunks as the primary LLM context. Preserve server order; do not re-sort unless you have a deliberate reranking step.

9. Turning search results into LLM prompts

Practical guidance from essentials/v2/api-results.mdx:
  • Preserve the order of chunks; it is the server ranking.
  • Use graph context only when it helps the question.
  • Use additional_context to attach forcefully related chunks by chunk_uuid / extra_context_ids.
  • For personalized answers, type: "all" is simplest: one result set already merges knowledge and memories.
  • Do not pass raw JSON directly to the LLM if token budget matters; use the SDK formatting helper to produce a compact context string.
  • Include a grounding instruction: answer only from provided context, and say when context is insufficient.
Use the SDK helper from essentials/v2/api-results.mdx:
  • Python: build_string(result) from hydra_db.helpers
  • TypeScript: buildString(result) from @hydradb/sdk
Python:
TypeScript:
Common mistakes:

10. Metadata guide

Database schema

Declared at POST /databases:
Field options:

Where metadata belongs

Rules:
  • Plan hot filter fields before first ingest; undeclared scope keys can be ignored.
  • Use exact equality filters; range/contains/fuzzy matching should be in the query or downstream reranker.
  • To change metadata on an indexed context item, re-ingest with the same id and upsert: true.
  • Do not rename metadata keys without re-ingesting affected sources.

11. Browse, fetch, relations, delete

List documents or memories

POST /context/list · client.context.list()
Parameters:
  • database
  • collection
  • type: "knowledge" | "memory"
  • ids
  • page, page_size (1–100)
  • filters.tenant_metadata
  • filters.additional_metadata
  • filters.source_fields
  • include_fields for projection

Fetch original content

GET /context/inspect · client.context.inspect()
Modes:

Inspect graph relations

GET /context/relations · client.context.relations()
Use it for graph debugging and provenance inspection. It supports pagination via cursor.

Delete sources or memories

DELETE /context · client.context.delete()
Use type: "memory" to delete memory IDs.

12. Error handling

HTTP status codes

Common error codes

Retry only 429, 500, 503; use bounded exponential backoff with jitter. SDK errors:

13. Cookbook patterns

The cookbooks show production patterns. Click the links below to read the raw Markdown guides with complete setup code and schemas: Common architecture across cookbooks:
  1. Create database and schema for hot filters.
  2. Ingest shared knowledge/app sources with stable IDs.
  3. Ingest user/session memories with collection.
  4. Poll status or use webhooks.
  5. Query /query with type: "knowledge", "memory", or "all".
  6. Format chunks, graph paths, and additional context into an LLM prompt.
  7. Cite sources and handle missing context explicitly.

14. Common mistakes checklist

  • Forgetting API-Version: 2 in raw HTTP calls.
  • Parsing raw HTTP response from the top level instead of data.
  • Assuming SDK responses include the raw envelope; SDKs unwrap data.
  • Searching immediately after database creation without polling readiness.
  • Searching immediately after ingestion without polling context.status or using webhooks.
  • Treating processing/queued content as searchable.
  • Not handling both errored and failed as failure statuses.
  • Omitting collection for user memories.
  • Writing with one collection and reading with another.
  • Using metadata filters for user partitioning instead of collection.
  • Using undeclared tenant_metadata keys in metadata_filters.
  • Putting hot filters in free-form metadata instead of database schema.
  • Expecting query_forceful_relations to work in mode: "fast".
  • Setting graph_context: false and expecting graph fields.
  • Re-sorting chunks before prompting without a deliberate reranker.
  • Passing too many chunks to the LLM.
  • Using operator without query_by: "text".
  • Forgetting to verify webhook signatures when a signing secret is configured.

15. SDK Method Reference

15.1 TypeScript SDK

15.2 Python SDK

15.3 Minimal cURL example

Use type on raw /query requests to select knowledge, memory, or all. The raw API response is wrapped; read payloads from .data.

15.4 Raw HTTP: ingest app-source knowledge

Use this for connector output where your app already extracted the text. app_knowledge must be a JSON string in multipart form data.
Search it with app-aware retrieval:

16. Navigation and support

  • Docs root for v2: get-started/v2, essentials/v2, api-reference/v2, cookbooks/v2
  • API reference OpenAPI: api-reference/v2/openapi.json
  • Python package: hydradb-sdk>=2,<3
  • TypeScript package: @hydradb/sdk@^2
  • Dashboard/API keys: https://app.hydradb.com
  • Support email in docs: [email protected]