localvectordb_server.utils.schema module

Shared utilities for metadata schema parsing and validation.

This module provides canonical implementations for parsing metadata schema configurations across different parts of the LocalVectorDB server, ensuring consistent validation and error handling.

localvectordb_server.utils.schema.parse_metadata_schema(schema_data: Dict[str, Any]) Dict[str, MetadataField]

Parse metadata schema from configuration data with validation.

This is the canonical implementation for parsing metadata schema configurations across the LocalVectorDB server. It handles both simple string type specifications and full field configuration dictionaries.

Parameters:

schema_data (Dict[str, Any]) – The schema data to parse. Can be: - Empty dict for no schema - Dict mapping field names to type strings (e.g., {“title”: “text”}) - Dict mapping field names to configuration dicts (e.g., {“title”: {“type”: “text”, “indexed”: true}})

Returns:

Parsed metadata schema with validated fields

Return type:

Dict[str, MetadataField]

Raises:

ValidationError – If the schema data is invalid or contains unsafe field names

Examples

Simple string types: >>> parse_metadata_schema({“title”: “text”, “created_at”: “date”})

Full configuration: >>> parse_metadata_schema({ … “title”: {“type”: “text”, “indexed”: True, “required”: False}, … “score”: {“type”: “real”, “indexed”: False, “required”: True} … })