haematite-cli 0.21.3

The haematite command: serve a store, its door and Studio, answer MCP, query with jq, and host the store's assistant seat
Documentation
use std::num::NonZeroUsize;

use serde_json::value::RawValue;

use super::Context;
use crate::serve::protocol::QueryRequest;
use crate::serve::query::parser::{Plan, Question, Stage};
use crate::serve::service::{Service, not_configured};
use crate::serve::storage::Failure;

#[cfg(test)]
#[path = "shape_tests.rs"]
mod shape_tests;

/// Read a page without a service embedding worker.
///
/// # Errors
/// Every refusal of the query, including `embed_not_configured` for words.
pub fn run(
    context: &Context<'_>,
    request: &QueryRequest,
    response_byte_limit: Option<NonZeroUsize>,
) -> Result<Box<RawValue>, Failure> {
    super::served(context, request, response_byte_limit, None)
}

/// Name an unavailable embedding worker before capturing or reading records.
pub(super) fn ready(service: Option<&Service>, plan: Option<&Plan>) -> Result<(), Failure> {
    if plan.is_some_and(|plan| {
        plan.stages.iter().any(|stage| {
            matches!(
                stage.value,
                Stage::Similar {
                    question: Question::Text(_),
                    ..
                } | Stage::Rerank {
                    question: Question::Text(_),
                    ..
                }
            )
        })
    }) {
        service
            .and_then(Service::embedding)
            .ok_or_else(not_configured)?
            .asker()?;
    }
    Ok(())
}