runifold_retrieval/
error.rs1use thiserror::Error;
2
3use crate::DocumentId;
4
5#[derive(Clone, Debug, Eq, Error, PartialEq)]
7#[non_exhaustive]
8pub enum RetrievalError {
9 #[error("document id cannot be empty")]
11 EmptyDocumentId,
12 #[error("document `{id}` cannot have empty text")]
14 EmptyDocumentText {
15 id: DocumentId,
17 },
18 #[error("retrieval query cannot be empty")]
20 EmptyQuery,
21 #[error("retrieval limit must be greater than zero")]
23 ZeroLimit,
24 #[error("embedding cannot be empty")]
26 EmptyEmbedding,
27 #[error("embedding coordinate {index} must be finite")]
29 NonFiniteEmbedding {
30 index: usize,
32 },
33 #[error("embedding coordinate {index} is outside the backend numeric range")]
35 EmbeddingCoordinateOutOfRange {
36 index: usize,
38 },
39 #[error("embedding must have a non-zero norm")]
41 ZeroNormEmbedding,
42 #[error("embedding dimension mismatch: expected {expected}, received {actual}")]
44 DimensionMismatch {
45 expected: usize,
47 actual: usize,
49 },
50 #[error("embedding count mismatch: expected {expected}, received {actual}")]
52 EmbeddingCountMismatch {
53 expected: usize,
55 actual: usize,
57 },
58 #[error("embedding input {index} cannot be empty")]
60 EmptyEmbeddingInput {
61 index: usize,
63 },
64 #[error("duplicate document id `{0}`")]
66 DuplicateDocument(DocumentId),
67 #[error("reranker candidate multiplier must produce between 1 and 1000 candidates")]
69 InvalidRerankCandidateLimit,
70 #[error("reranker returned an invalid result: {message}")]
72 InvalidRerankOutput {
73 message: String,
75 },
76 #[error("hybrid retrieval weights and rank constant must be finite and positive")]
78 InvalidHybridConfiguration,
79 #[error("hybrid source returned duplicate document id `{0}`")]
81 DuplicateHybridResult(DocumentId),
82 #[error("retriever capability `{name}` is not granted")]
84 CapabilityDenied {
85 name: String,
87 },
88 #[error("retrieval was cancelled")]
90 Cancelled,
91 #[error("retrieval deadline exceeded")]
93 DeadlineExceeded,
94 #[error("retrieval provider failed: {message}")]
96 Provider {
97 message: String,
99 },
100 #[error("retrieval usage counter overflow")]
102 UsageOverflow,
103}
104
105impl RetrievalError {
106 pub fn provider(message: impl Into<String>) -> Self {
109 Self::Provider {
110 message: message.into(),
111 }
112 }
113}