Skip to main content

Crate anda_db_schema

Crate anda_db_schema 

Source
Expand description

§anda_db_schema

Type system and schema definitions for Anda DB, the embedded knowledge & memory database for AI Agents.

This crate provides the building blocks used across all Anda DB sub-crates:

  • FieldType (alias Ft): a closed enum of every type a field may declare, including primitive, composite (Array, Map) and Option variants.
  • FieldValue (alias Fv): the runtime representation of an actual value. It can losslessly round-trip with Cbor and is serde-compatible for both human-readable (JSON) and binary (CBOR) formats.
  • FieldEntry (alias Fe): metadata for a single field — name, type, description, uniqueness flag and a stable numeric idx used as the on-disk key (instead of the field name) to keep records compact.
  • Schema / SchemaBuilder: an ordered, versioned collection of FieldEntry values. Schemas are versioned and support forward-compatible migration via Schema::upgrade_with.
  • Document / DocumentOwned: schema-bound and standalone document representations.
  • Resource: a predefined struct describing an external resource (file, blob, URI…) referenced from a document.

§Derive macros

Two macros are re-exported from anda_db_derive:

  • AndaDBSchema — generates a schema() constructor from a Rust struct.
  • FieldTyped — generates a field_type() constructor returning the nested FieldType::Map describing the struct’s layout.

See the crate-level guide in docs/anda_db_schema.md for a full tour and SCHEMA.md for the on-disk format.

§Storage format

All values are normalized to CBOR for persistence. The CBOR encoding is deterministic and small; floating point values disallow NaN so that FieldValue keeps a meaningful PartialEq.

Structs§

ByteArrayB64
Wrapper around [u8; N] to serialize and deserialize efficiently. If the serialization format is human readable (formats like JSON and YAML), it will be encoded in Base64URL. Otherwise, it will be serialized as a byte array.
ByteBufB64
Wrapper around Vec<u8> to serialize and deserialize efficiently. If the serialization format is human readable (formats like JSON and YAML), it will be encoded in Base64URL. Otherwise, it will be serialized as a byte array.
Document
A single Anda DB document together with its Schema.
DocumentOwned
A standalone document without an attached Schema.
FieldEntry
Metadata for a single field in a Schema.
Map
Re-export Map from serde_json Represents a JSON key/value type.
Resource
Represents a resource for AI Agents.
Schema
Document schema definition for Anda DB.
SchemaBuilder
SchemaBuilder is used to construct a Schema instance. It provides methods to add fields and build the final schema.
bf16
Re-export bf16 from half crate A 16-bit floating point type implementing the bfloat16 format.

Enums§

FieldKey
A key in a FieldType::Map / FieldValue::Map.
FieldType
The type of a field declared in a Schema.
FieldValue
The runtime value of a field.
SchemaError
Errors produced when building, validating or (de)serializing a schema, a field entry, or a field value.

Statics§

BYTES_WILDCARD_KEY
The wildcard byte key (b"*") used to express a homogeneous Map<Bytes, T>.
TEXT_WILDCARD_KEY
The wildcard text key ("*") used to express a homogeneous Map<Text, T>.

Functions§

validate_field_name
Validate a field name against Anda DB’s naming rules.
vector_from_f32
Convert a Vec<f32> into a Vector (i.e. Vec<bf16>) by lossy conversion of every element.
vector_from_f64
Convert a Vec<f64> into a Vector (i.e. Vec<bf16>) by lossy conversion of every element.

Type Aliases§

BoxError
A boxed, thread-safe std::error::Error.
Cbor
Type alias for cbor2::Value
DocumentId
The unique identifier for a document within a collection.
Fe
Type alias for FieldEntry
Ft
Type alias for FieldType
Fv
Type alias for FieldValue
IndexedFieldValues
Type alias for BTreeMap<usize, FieldValue>, the canonical container for a document’s field values.
Json
Type alias for serde_json::Value
Vector
Type alias for Vec<bf16>

Derive Macros§

AndaDBSchema
A derive macro that generates a schema() associated function for a struct.
FieldTyped
A derive macro that generates a field_type() associated function for a struct.