1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! RAG (Retrieval-Augmented Generation) support with pgvector
//!
//! This module provides integration with PostgreSQL + pgvector for
//! semantic search and context retrieval during inference, with an
//! AWS Bedrock Knowledge Bases-style API.
//!
//! # Knowledge Base API (Recommended)
//!
//! ```rust,ignore
//! use llama_gguf::rag::{KnowledgeBase, KnowledgeBaseBuilder, DataSource, ChunkingStrategy};
//!
//! // Create a knowledge base with the builder
//! let kb = KnowledgeBaseBuilder::new("my-kb")
//! .description("Documentation knowledge base")
//! .fixed_size_chunking(300, 20) // 300 tokens, 20% overlap
//! .max_results(5)
//! .create()
//! .await?;
//!
//! // Ingest documents
//! kb.ingest(DataSource::Directory {
//! path: "./docs".into(),
//! pattern: Some("**/*.md".into()),
//! recursive: true,
//! }).await?;
//!
//! // Retrieve and generate
//! let response = kb.retrieve_and_generate("What is the main feature?", None).await?;
//! println!("Answer: {}", response.output);
//!
//! // Print citations
//! for citation in response.citations {
//! println!("Source: {} (score: {:.2})", citation.source.uri, citation.score);
//! }
//! ```
//!
//! # Low-Level Store API
//!
//! For direct vector store access:
//!
//! ```rust,ignore
//! use llama_gguf::rag::{RagConfig, RagStore, MetadataFilter};
//!
//! let config = RagConfig::load(Some("rag.toml"))?;
//! let store = RagStore::connect(config).await?;
//!
//! // Search with filters
//! let filter = MetadataFilter::eq("type", "documentation");
//! let results = store.search_with_filter(&query_embedding, Some(5), Some(filter)).await?;
//! ```
//!
//! # Setup
//!
//! 1. Install pgvector extension in PostgreSQL:
//! ```sql
//! CREATE EXTENSION vector;
//! ```
//!
//! 2. Configure connection in `rag.toml` or via environment:
//! ```toml
//! [database]
//! connection_string = "postgres://user:pass@localhost/db"
//!
//! [embeddings]
//! dimension = 384
//! ```
pub use *;
pub use *;
pub use *;
pub use example_config;
pub use *;
use Error;
/// RAG-related errors
pub type RagResult<T> = ;