use super::{Entity, Note, SubstrateKind, TextDocument};
pub fn entity_embedding_text(entity: &Entity) -> String {
let mut text = entity.name.clone();
for alias in &entity.aliases {
text.push(' ');
text.push_str(&alias.alias);
}
if let Some(description) = entity.description.as_deref().filter(|d| !d.is_empty()) {
text.push(' ');
text.push_str(description);
}
text
}
pub fn note_embedding_text(note: &Note) -> String {
note_embedding_text_ref(note).to_owned()
}
pub(crate) fn note_embedding_text_ref(note: &Note) -> &str {
¬e.content
}
pub fn entity_fts_document(entity: &Entity) -> TextDocument {
let updated_at =
chrono::DateTime::from_timestamp_micros(entity.updated_at).unwrap_or_else(chrono::Utc::now);
TextDocument {
subject_id: entity.id,
kind: SubstrateKind::Entity,
record_kind: Some(entity.kind.clone()),
title: Some(entity.name.clone()),
body: entity_embedding_text(entity),
tags: entity.tags.clone(),
namespace: entity.namespace.clone(),
metadata: entity.properties.clone(),
updated_at,
}
}
pub fn note_fts_document(note: &Note) -> TextDocument {
let body = match ¬e.name {
Some(n) => format!("{n} {}", note.content),
None => note.content.clone(),
};
let updated_at =
chrono::DateTime::from_timestamp_micros(note.updated_at).unwrap_or_else(chrono::Utc::now);
TextDocument {
subject_id: note.id,
kind: SubstrateKind::Note,
record_kind: Some(note.kind.clone()),
title: note.name.clone(),
body,
tags: vec![],
namespace: note.namespace.clone(),
metadata: note.properties.clone(),
updated_at,
}
}