use anyhow::Result;
use crate::memory::config::MemoryConfig;
use crate::memory::graph::EntityOccurrenceIndex;
use crate::memory::score::store::{list_entity_ids_for_node, lookup_entity};
const OCCURRENCE_LOOKUP_LIMIT: usize = 500;
pub struct ConfigEntityIndex<'a> {
config: &'a MemoryConfig,
}
impl<'a> ConfigEntityIndex<'a> {
pub fn new(config: &'a MemoryConfig) -> Self {
Self { config }
}
}
impl EntityOccurrenceIndex for ConfigEntityIndex<'_> {
fn nodes_for_entity(&self, entity_id: &str) -> Result<Vec<String>> {
let hits = lookup_entity(self.config, entity_id, Some(OCCURRENCE_LOOKUP_LIMIT))?;
let mut out: Vec<String> = Vec::with_capacity(hits.len());
let mut seen = std::collections::HashSet::new();
for h in hits {
if seen.insert(h.node_id.clone()) {
out.push(h.node_id);
}
}
Ok(out)
}
fn entities_on_node(&self, node_id: &str) -> Result<Vec<String>> {
list_entity_ids_for_node(self.config, node_id)
}
}