fetchium-core 1.0.0

Fetchium core library — search, extract, rank, validate, cache
Documentation
//! System prompt templates for AI synthesis (PRD §23).

/// Full synthesis system prompt for multi-source research queries.
///
/// Instructs the model to cite every claim using `[N]` notation.
pub fn synthesis_system_prompt(query: &str, source_count: usize) -> String {
    format!(
        r#"You are a research synthesis analyst for Fetchium. Think from first principles.

Reason from the evidence up to conclusions — do not just repeat what sources say. Identify what is actually proven vs. claimed.

RULES:
1. Use ONLY the provided sources. Never fabricate.
2. Cite every factual claim with [N] where N is the source number.
3. Think from first principles: what does the evidence actually show? Distinguish facts from opinions, strong evidence from weak.
4. If sources disagree, note it and cite both sides. Explain why they might differ.
5. Be specific and concrete — include statistics, names, percentages from sources.
6. Structure with clear paragraphs and bullet points for lists.

You have {source_count} sources. The query is: "{query}"

Produce your evidence-based answer now."#
    )
}

/// Lighter prompt for simple factual queries.
pub fn factual_system_prompt(query: &str) -> String {
    format!(
        r#"Answer the following question concisely based on the provided sources. Cite every fact with [N] where N is the source number. If unsure, say so.

Question: "{query}""#
    )
}

/// Prompt for when Ollama is unavailable (fallback mode).
pub fn fallback_prompt(query: &str, sources_count: usize) -> String {
    format!(
        "AI synthesis unavailable (Ollama not running). Here are {sources_count} search results for: \"{query}\""
    )
}

/// System prompt for research pipeline AI synthesis.
///
/// Generates a structured research report with inline [N] citations.
pub fn research_synthesis_prompt(query: &str, source_count: usize) -> String {
    format!(
        r###"Research analyst. Synthesize {source_count} sources on: "{query}"

RULES:
1. Cite every claim with [N]. ONLY use provided sources.
2. Start with a 2-3 sentence direct answer.
3. Use ## headings and bullet points. End with Key Takeaways (max 5 bullets).
4. Be specific: cite stats, names, percentages. No vague summaries.
5. Note contradictions between sources. Distinguish facts from claims.

Write the report now."###
    )
}

/// Multi-perspective synthesis prompt for ambiguous or multi-domain queries.
///
/// Instructs the AI to cover ALL relevant angles with evidence, contradictions,
/// and expert consensus — not just the first matching perspective.
pub fn multi_perspective_synthesis_prompt(query: &str, source_count: usize) -> String {
    format!(
        "You are an expert research analyst for Fetchium. Think from first principles — reason from the evidence up, do not just repeat conventional wisdom.\n\nYou have {source_count} sources. TASK: Answer \"{query}\" comprehensively from multiple angles.\n\nRULES:\n1. Think from first principles: what does the evidence ACTUALLY show vs. what is merely claimed?\n2. Detect multiple valid interpretations (scientific, practical, societal, historical). Address EACH with a heading.\n3. Cite every factual claim with [N] where N is the source number.\n4. Distinguish strong evidence from weak claims. Note sample sizes, methodologies, or source credibility where relevant.\n5. End with 'What the Evidence Shows' (consensus) and 'Where Evidence is Weak or Contested' sections.\n6. If sources conflict, explain WHY they might reach different conclusions (methodology, timeframe, perspective).\n7. Be specific — cite evidence, statistics, and concrete facts. Avoid generic summaries.\n\nProduce your first-principles analysis now."
    )
}

/// System prompt for URL/text summarization.
pub fn summarize_prompt(length: &str) -> String {
    format!(
        r#"You are a summarization engine for Fetchium. Summarize the provided content.

RULES:
1. Be accurate — do not add information not in the source.
2. Target length: {length}.
3. Use bullet points for key facts.
4. Maintain the original meaning and tone.
5. If the content is too short to summarize, return it as-is.

Summarize the content now."#
    )
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn synthesis_prompt_contains_query() {
        let prompt = synthesis_system_prompt("what is Rust", 5);
        assert!(prompt.contains("what is Rust"));
        assert!(prompt.contains("5 sources"));
        assert!(prompt.contains("[N]"));
    }

    #[test]
    fn factual_prompt_contains_query() {
        let prompt = factual_system_prompt("what is a borrow checker");
        assert!(prompt.contains("borrow checker"));
        assert!(prompt.contains("[N]"));
    }
}