Expand description
Metadata storage for vector annotations. Metadata storage system for EdgeVec.
This module provides a type-safe metadata storage system for attaching key-value pairs to vectors. Metadata enables filtering, sorting, and enriching vector search results with additional context.
§Features
- 5 Value Types: String, Integer, Float, Boolean, StringArray
- Type-Safe: Strongly typed values with accessor methods
- Validated: Keys and values are validated against limits
- Serializable: JSON serialization with clear type tags
§Quick Start
use edgevec::metadata::{MetadataValue, MetadataStore};
use edgevec::metadata::validation::validate_key_value;
// Create values using constructors
let title = MetadataValue::String("Hello World".to_string());
let count = MetadataValue::Integer(42);
let score = MetadataValue::Float(0.95);
let active = MetadataValue::Boolean(true);
let tags = MetadataValue::StringArray(vec!["rust".into(), "wasm".into()]);
// Create values using From trait
let title: MetadataValue = "Hello World".into();
let count: MetadataValue = 42i64.into();
let active: MetadataValue = true.into();
// Validate before storing
assert!(validate_key_value("title", &title).is_ok());
// Check types
assert!(title.is_string());
assert!(count.is_integer());
// Extract values
assert_eq!(title.as_string(), Some("Hello World"));
assert_eq!(count.as_integer(), Some(42));§Value Types
| Type | Rust | JSON | Use Case |
|---|---|---|---|
| String | String | string | Titles, descriptions |
| Integer | i64 | number | Counts, IDs, timestamps |
| Float | f64 | number | Scores, weights |
| Boolean | bool | boolean | Flags, filters |
| StringArray | Vec<String> | string[] | Tags, categories |
§Validation Limits
| Limit | Value | Description |
|---|---|---|
| Max keys per vector | 64 | Prevents memory bloat |
| Max key length | 256 bytes | Reasonable for field names |
| Max string value | 64KB | Prevents abuse |
| Max array elements | 1,024 | Prevents excessive arrays |
§JSON Serialization
Values serialize with adjacently-tagged representation:
{"type": "string", "value": "hello"}
{"type": "integer", "value": 42}
{"type": "float", "value": 2.5}
{"type": "boolean", "value": true}
{"type": "string_array", "value": ["a", "b"]}§Module Structure
types- CoreMetadataValueenumerror-MetadataErrorenumvalidation- Validation constants and functionsstore-MetadataStorefor CRUD operations (Day 2)
Modules§
- validation
- Metadata validation rules and constants.
Structs§
- Metadata
Store - Storage for vector metadata.
Enums§
- Metadata
Error - Errors that can occur during metadata operations.
- Metadata
Value - Supported metadata value types.
- Serialization
Error - Errors that can occur during metadata serialization/deserialization.