Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

2.1 KB
Raw Blame
mod citation;
mod grounded;
mod index;
mod pack;
mod passage;
mod prompt;

use thiserror::Error;

#[derive(Debug, Error)]
pub enum RetrievalError {
    #[error("invalid retrieval input: {0}")]
    InvalidInput(String),
    #[error("invalid knowledge pack: {0}")]
    InvalidPack(String),
    #[error("knowledge pack I/O failed: {0}")]
    Io(#[from] std::io::Error),
    #[error("knowledge pack JSON failed: {0}")]
    Json(#[from] serde_json::Error),
    #[error("knowledge pack metadata decompression failed: {0}")]
    Zstd(String),
}

fn normalize_single_line(value: &str) -> String {
    value
        .chars()
        .map(|character| {
            if character.is_control() {
                ' '
            } else {
                character
            }
        })
        .collect::<String>()
        .split_whitespace()
        .collect::<Vec<_>>()
        .join(" ")
}

const BEGIN_CONTEXT_SENTINEL: &str = "----- BEGIN KNOWLEDGE CONTEXT -----";
const END_CONTEXT_SENTINEL: &str = "----- END KNOWLEDGE CONTEXT -----";

pub use citation::{
    MAX_GROUNDED_SOURCES, ParsedAssistantText, ParsedGroundedAssistantText, SourceCitation,
    clean_assistant_text, finalize_assistant_text, finalize_grounded_assistant_text,
    grounded_source_chip_labels, knowledge_source_chip_label, parse_assistant_text,
    parse_grounded_assistant_text,
};
pub use grounded::{
    GroundedExcerpt, GroundedPromptContext, GroundedSource, MAX_NOTES_GROUNDING_HITS,
    ReferencedPassage, build_grounded_prompt_context, select_mixed_grounding_candidates,
};
pub use index::{RetrievalHit, RetrievalIndex};
pub use pack::{
    KnowledgeReconciliation, KnowledgeReconciliationStatus,
    cleanup_obsolete_knowledge_pack_revisions, knowledge_asset, knowledge_pack_root,
    reconcile_knowledge_pack,
};
pub use prompt::{KnowledgePromptContext, KnowledgePromptHit, build_knowledge_prompt_context};

pub(crate) use grounded::{MAX_GROUNDING_HITS, MAX_PACK_HITS, build_followup_prompt_context};
pub(crate) use passage::clean_passage_text;
pub use passage::{IncludedPassage, PassageLocator, PassageSpan};

#[cfg(test)]
pub(crate) use passage::tests::passage_fixture;