localvectordb.section_metadata module

Section metadata extractors for hierarchical document embeddings.

Extractors automatically populate section metadata during ingestion. Built-in extractors are text-based (no external dependencies). Users can provide custom extractors by subclassing SectionMetadataExtractor.

class localvectordb.section_metadata.SectionMetadataExtractor

Bases: ABC

Base class for section metadata extractors.

name: str = ''
requires_llm: bool = False
abstractmethod extract(section_text: str, heading: str | None, context: Dict[str, Any]) Dict[str, Any]

Extract metadata from a section.

Parameters:
  • section_text (str) – The full text of the section.

  • heading (Optional[str]) – The section heading, if any.

  • context (Dict[str, Any]) – Additional context (e.g., document metadata, other sections).

Returns:

Metadata key-value pairs to merge into section.metadata.

Return type:

Dict[str, Any]

class localvectordb.section_metadata.WordCountExtractor

Bases: SectionMetadataExtractor

Extracts word count for a section.

name: str = 'word_count'
extract(section_text: str, heading: str | None, context: Dict[str, Any]) Dict[str, Any]

Extract metadata from a section.

Parameters:
  • section_text (str) – The full text of the section.

  • heading (Optional[str]) – The section heading, if any.

  • context (Dict[str, Any]) – Additional context (e.g., document metadata, other sections).

Returns:

Metadata key-value pairs to merge into section.metadata.

Return type:

Dict[str, Any]

class localvectordb.section_metadata.CharCountExtractor

Bases: SectionMetadataExtractor

Extracts character count for a section.

name: str = 'char_count'
extract(section_text: str, heading: str | None, context: Dict[str, Any]) Dict[str, Any]

Extract metadata from a section.

Parameters:
  • section_text (str) – The full text of the section.

  • heading (Optional[str]) – The section heading, if any.

  • context (Dict[str, Any]) – Additional context (e.g., document metadata, other sections).

Returns:

Metadata key-value pairs to merge into section.metadata.

Return type:

Dict[str, Any]

class localvectordb.section_metadata.HeadingPathExtractor

Bases: SectionMetadataExtractor

Extracts hierarchical heading path (e.g., ‘Chapter 1 > Introduction > Background’).

Requires ‘all_sections’ key in context with list of (heading, heading_level) tuples.

name: str = 'heading_path'
extract(section_text: str, heading: str | None, context: Dict[str, Any]) Dict[str, Any]

Extract metadata from a section.

Parameters:
  • section_text (str) – The full text of the section.

  • heading (Optional[str]) – The section heading, if any.

  • context (Dict[str, Any]) – Additional context (e.g., document metadata, other sections).

Returns:

Metadata key-value pairs to merge into section.metadata.

Return type:

Dict[str, Any]

class localvectordb.section_metadata.KeywordsExtractor(top_n: int = 10, min_word_length: int = 3)

Bases: SectionMetadataExtractor

Extracts top-N keywords from a section using simple word frequency.

Parameters:
  • top_n (int) – Number of top keywords to extract. Default: 10.

  • min_word_length (int) – Minimum word length to consider. Default: 3.

name: str = 'keywords'
__init__(top_n: int = 10, min_word_length: int = 3)
extract(section_text: str, heading: str | None, context: Dict[str, Any]) Dict[str, Any]

Extract metadata from a section.

Parameters:
  • section_text (str) – The full text of the section.

  • heading (Optional[str]) – The section heading, if any.

  • context (Dict[str, Any]) – Additional context (e.g., document metadata, other sections).

Returns:

Metadata key-value pairs to merge into section.metadata.

Return type:

Dict[str, Any]

localvectordb.section_metadata.resolve_extractors(extractors: List[str | SectionMetadataExtractor] | None) List[SectionMetadataExtractor]

Resolve a list of extractor names/instances to extractor instances.

Parameters:

extractors (Optional[List[Union[str, SectionMetadataExtractor]]]) – List of extractor names (for built-ins) or instances.

Returns:

List of ready-to-use extractor instances.

Return type:

List[SectionMetadataExtractor]