1use crate::error::VectorError;
8use crate::PgVectorStore;
9use crate::{SearchResult, VectorMetric, VectorRecord};
10use async_trait::async_trait;
11
12pub struct StubVectorStore;
17
18impl StubVectorStore {
19 pub fn new() -> Self {
20 Self
21 }
22}
23
24impl Default for StubVectorStore {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29
30#[async_trait]
31impl PgVectorStore for StubVectorStore {
32 async fn create_collection(
33 &self,
34 _name: &str,
35 _dimension: usize,
36 _metric: Option<VectorMetric>,
37 ) -> Result<(), VectorError> {
38 Err(VectorError::Unsupported(
39 "StubVectorStore does not support create_collection".to_string(),
40 ))
41 }
42
43 async fn delete_collection(&self, _name: &str) -> Result<(), VectorError> {
44 Err(VectorError::Unsupported(
45 "StubVectorStore does not support delete_collection".to_string(),
46 ))
47 }
48
49 async fn insert(
50 &self,
51 _collection: &str,
52 _records: Vec<VectorRecord>,
53 ) -> Result<(), VectorError> {
54 Err(VectorError::Unsupported(
55 "StubVectorStore does not support insert".to_string(),
56 ))
57 }
58
59 async fn search(
60 &self,
61 _collection: &str,
62 _query: &[f32],
63 _top_k: usize,
64 ) -> Result<Vec<SearchResult>, VectorError> {
65 Err(VectorError::Unsupported(
66 "StubVectorStore does not support search".to_string(),
67 ))
68 }
69
70 async fn get(&self, _collection: &str, _id: &str) -> Result<Option<VectorRecord>, VectorError> {
71 Err(VectorError::Unsupported(
72 "StubVectorStore does not support get".to_string(),
73 ))
74 }
75
76 async fn delete(&self, _collection: &str, _ids: Vec<String>) -> Result<u64, VectorError> {
77 Err(VectorError::Unsupported(
78 "StubVectorStore does not support delete".to_string(),
79 ))
80 }
81
82 async fn count(&self, _collection: &str) -> Result<usize, VectorError> {
83 Err(VectorError::Unsupported(
84 "StubVectorStore does not support count".to_string(),
85 ))
86 }
87}
88
89#[cfg(test)]
90mod tests {
91 use super::*;
92
93 #[tokio::test]
94 async fn test_stub_create_collection_unsupported() {
95 let stub = StubVectorStore::new();
96 let result = stub.create_collection("docs", 3, None).await;
97 assert!(matches!(result, Err(VectorError::Unsupported(_))));
98 }
99
100 #[tokio::test]
101 async fn test_stub_insert_unsupported() {
102 let stub = StubVectorStore::new();
103 let rec = VectorRecord::new("r1", vec![1.0, 0.0, 0.0]);
104 let result = stub.insert("docs", vec![rec]).await;
105 assert!(matches!(result, Err(VectorError::Unsupported(_))));
106 }
107
108 #[tokio::test]
109 async fn test_stub_search_unsupported() {
110 let stub = StubVectorStore::new();
111 let result = stub.search("docs", &[1.0, 0.0, 0.0], 5).await;
112 assert!(matches!(result, Err(VectorError::Unsupported(_))));
113 }
114
115 #[tokio::test]
116 async fn test_stub_get_unsupported() {
117 let stub = StubVectorStore::new();
118 let result = stub.get("docs", "r1").await;
119 assert!(matches!(result, Err(VectorError::Unsupported(_))));
120 }
121
122 #[tokio::test]
123 async fn test_stub_delete_unsupported() {
124 let stub = StubVectorStore::new();
125 let result = stub.delete("docs", vec!["r1".to_string()]).await;
126 assert!(matches!(result, Err(VectorError::Unsupported(_))));
127 }
128
129 #[tokio::test]
130 async fn test_stub_count_unsupported() {
131 let stub = StubVectorStore::new();
132 let result = stub.count("docs").await;
133 assert!(matches!(result, Err(VectorError::Unsupported(_))));
134 }
135
136 #[tokio::test]
137 async fn test_stub_delete_collection_unsupported() {
138 let stub = StubVectorStore::new();
139 let result = stub.delete_collection("docs").await;
140 assert!(matches!(result, Err(VectorError::Unsupported(_))));
141 }
142
143 #[tokio::test]
144 async fn test_stub_default() {
145 let stub = StubVectorStore;
146 let result = stub.count("any").await;
147 assert!(matches!(result, Err(VectorError::Unsupported(_))));
148 }
149}