Skip to main content

weavatrix_memory/extraction/
provider.rs

1use super::{ExtractionInput, ExtractionOutput};
2use std::{error::Error, fmt};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct ExtractionError {
6    pub provider: String,
7    pub message: String,
8}
9
10impl ExtractionError {
11    #[must_use]
12    pub fn new(provider: impl Into<String>, message: impl Into<String>) -> Self {
13        Self {
14            provider: provider.into(),
15            message: message.into(),
16        }
17    }
18}
19
20impl fmt::Display for ExtractionError {
21    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
22        write!(
23            formatter,
24            "extraction provider {} failed: {}",
25            self.provider, self.message
26        )
27    }
28}
29
30impl Error for ExtractionError {}
31
32/// Converts source material into typed mentions and relations.
33///
34/// Providers may wrap AST parsers, issue trackers, language models, or future
35/// Weavatrix search packages. The memory core owns validation, entity linking,
36/// provenance, and event creation.
37pub trait ExtractionProvider: Sync {
38    fn name(&self) -> &str;
39
40    /// Extracts candidates without mutating memory.
41    ///
42    /// # Errors
43    ///
44    /// Returns a provider-labelled failure. The engine rejects failures whose
45    /// provider identity does not match [`Self::name`].
46    fn extract(&self, input: &ExtractionInput) -> Result<ExtractionOutput, ExtractionError>;
47}