Skip to main content

spire_ai/
lib.rs

1//! SpireAI — High-level AI SDK for SpireDB.
2//!
3//! Build RAG pipelines, semantic code search, and agent memory
4//! on top of SpireDB with minimal boilerplate.
5//!
6//! # Quick Start
7//!
8//! ```rust,no_run
9//! use spire_ai::prelude::*;
10//!
11//! #[derive(Doc, Serialize, Deserialize, Clone)]
12//! struct Article {
13//!     #[id]
14//!     slug: String,
15//!     title: String,
16//!     content: String,
17//! }
18//!
19//! #[tokio::main]
20//! async fn main() -> spire_ai::Result<()> {
21//!     let spire = Spire::connect("http://127.0.0.1:50051").await?;
22//!     let articles = spire.collection::<Article>("articles");
23//!     articles.ensure().await?;
24//!
25//!     articles.insert(&Article {
26//!         slug: "hello".into(),
27//!         title: "Hello World".into(),
28//!         content: "An introduction to SpireAI.".into(),
29//!     }).await?;
30//!
31//!     let hits = articles.search("introduction").run().await?;
32//!     for hit in hits {
33//!         println!("{}: {}", hit.score, hit.doc.title);
34//!     }
35//!     Ok(())
36//! }
37//! ```
38
39pub mod client;
40pub mod collection;
41pub mod document;
42pub mod embedding;
43pub mod error;
44pub mod llm;
45pub mod rag;
46pub mod search;
47pub mod types;
48pub mod watch;
49
50#[cfg(feature = "code")]
51pub mod code;
52
53pub mod filecache;
54
55pub mod agent;
56pub mod tool;
57
58// Re-exports
59pub use client::{Spire, SpireBuilder};
60pub use collection::Collection;
61pub use document::Doc;
62pub use error::{Error, Result};
63pub use filecache::FileCache;
64pub use search::{Filter, Hit, Search};
65pub use types::{IndexResult, IngestResult};
66pub use watch::{Change, WatchStream};
67
68#[cfg(feature = "macros")]
69pub use spire_ai_macros::Doc;
70
71/// Prelude — import everything you need with `use spire_ai::prelude::*`.
72pub mod prelude {
73    pub use crate::client::{Spire, SpireBuilder};
74    pub use crate::collection::Collection;
75    pub use crate::document::Doc;
76    pub use crate::embedding::Embedder;
77    pub use crate::error::{Error, Result};
78    pub use crate::rag::chunker::Chunk;
79    pub use crate::rag::{RagBuilder, RagPipeline, ScoredChunk};
80    pub use crate::search::{Filter, Hit, Search};
81    pub use crate::{Change, WatchStream};
82
83    #[cfg(feature = "code")]
84    pub use crate::code::{CodeChunk, CodeContext, CodeIndex};
85
86    pub use crate::filecache::{CacheStats, FileCache, ReadResult};
87
88    pub use crate::agent::{AgentLoop, AgentLoopConfig, AgentMemory};
89    pub use crate::llm::{ChatMessage, ChatResponse, ToolDef};
90    pub use crate::tool::{Tool, ToolRegistry, ToolResult};
91
92    #[cfg(feature = "macros")]
93    pub use spire_ai_macros::Doc;
94
95    pub use serde::{Deserialize, Serialize};
96}