Foresight.EntityExtractor behaviour (Foresight v0.1.0)

Copy Markdown View Source

Seam for deriving entity names from raw content.

This is the FALLBACK path only. When retain-time atomic-fact extraction is on, each fact already carries LLM-extracted entities that are threaded through to materialize_entities, mirroring Hindsight's fact.entities source (engine/retain/entity_processing.py:32). The extractor is invoked only when an item has no such entities — extraction is off, or entities are being rebuilt from stored content.

The default implementation is Foresight.EntityExtractors.Simple (a crude regex); the module is selected via the engine :entity_extractor config so it can be swapped without touching the storage layer.

An extractor may optionally implement extract/2 to receive the retain opts (:llm, :provider, :provider_opts, :sleep_ms) — Foresight.EntityExtractors.LLM needs the LLM handle. run/3 dispatches to extract/2 when present and otherwise to the pure extract/1, mirroring the function_exported? optional-callback dispatch used elsewhere (Foresight.LLM.supports_tool_calling?/1).

Summary

Callbacks

Return the entity names found in content (deduplicated).

Like extract/1 but with access to the retain opts (e.g. an :llm handle).

Functions

Invoke extractor on content, passing opts when the module implements the optional extract/2; otherwise the pure extract/1. opts is ignored by the latter.

Callbacks

extract(content)

@callback extract(content :: String.t()) :: [String.t()]

Return the entity names found in content (deduplicated).

extract(content, opts)

(optional)
@callback extract(content :: String.t(), opts :: keyword()) :: [String.t()]

Like extract/1 but with access to the retain opts (e.g. an :llm handle).

Functions

run(extractor, content, opts \\ [])

@spec run(module(), String.t(), keyword()) :: [String.t()]

Invoke extractor on content, passing opts when the module implements the optional extract/2; otherwise the pure extract/1. opts is ignored by the latter.