Skip to main content

reddb_server/application/
ports_impls_query.rs

1use super::*;
2impl RuntimeQueryPort for RedDBRuntime {
3    fn execute_query(&self, query: &str) -> RedDBResult<RuntimeQueryResult> {
4        RedDBRuntime::execute_query(self, query)
5    }
6
7    fn explain_query(&self, query: &str) -> RedDBResult<RuntimeQueryExplain> {
8        RedDBRuntime::explain_query(self, query)
9    }
10
11    fn scan_collection(
12        &self,
13        collection: &str,
14        cursor: Option<ScanCursor>,
15        limit: usize,
16    ) -> RedDBResult<ScanPage> {
17        RedDBRuntime::scan_collection(self, collection, cursor, limit)
18    }
19
20    fn search_similar(
21        &self,
22        collection: &str,
23        vector: &[f32],
24        k: usize,
25        min_score: f32,
26    ) -> RedDBResult<Vec<SimilarResult>> {
27        super::ensure_collection_model_read(
28            &self.db(),
29            collection,
30            crate::catalog::CollectionModel::Vector,
31        )?;
32        RedDBRuntime::search_similar(self, collection, vector, k, min_score)
33    }
34
35    fn search_ivf(
36        &self,
37        collection: &str,
38        vector: &[f32],
39        k: usize,
40        n_lists: usize,
41        n_probes: Option<usize>,
42    ) -> RedDBResult<RuntimeIvfSearchResult> {
43        super::ensure_collection_model_read(
44            &self.db(),
45            collection,
46            crate::catalog::CollectionModel::Vector,
47        )?;
48        RedDBRuntime::search_ivf(self, collection, vector, k, n_lists, n_probes)
49    }
50
51    fn search_hybrid(
52        &self,
53        vector: Option<Vec<f32>>,
54        query: Option<String>,
55        k: Option<usize>,
56        collections: Option<Vec<String>>,
57        entity_types: Option<Vec<String>>,
58        capabilities: Option<Vec<String>>,
59        graph_pattern: Option<RuntimeGraphPattern>,
60        filters: Vec<RuntimeFilter>,
61        weights: Option<RuntimeQueryWeights>,
62        min_score: Option<f32>,
63        limit: Option<usize>,
64    ) -> RedDBResult<DslQueryResult> {
65        RedDBRuntime::search_hybrid(
66            self,
67            vector,
68            query,
69            k,
70            collections,
71            entity_types,
72            capabilities,
73            graph_pattern,
74            filters,
75            weights,
76            min_score,
77            limit,
78        )
79    }
80
81    fn search_text(
82        &self,
83        query: String,
84        collections: Option<Vec<String>>,
85        entity_types: Option<Vec<String>>,
86        capabilities: Option<Vec<String>>,
87        fields: Option<Vec<String>>,
88        limit: Option<usize>,
89        fuzzy: bool,
90    ) -> RedDBResult<DslQueryResult> {
91        RedDBRuntime::search_text(
92            self,
93            query,
94            collections,
95            entity_types,
96            capabilities,
97            fields,
98            limit,
99            fuzzy,
100        )
101    }
102
103    fn search_multimodal(
104        &self,
105        query: String,
106        collections: Option<Vec<String>>,
107        entity_types: Option<Vec<String>>,
108        capabilities: Option<Vec<String>>,
109        limit: Option<usize>,
110    ) -> RedDBResult<DslQueryResult> {
111        RedDBRuntime::search_multimodal(self, query, collections, entity_types, capabilities, limit)
112    }
113
114    fn search_index(
115        &self,
116        index: String,
117        value: String,
118        exact: bool,
119        collections: Option<Vec<String>>,
120        entity_types: Option<Vec<String>>,
121        capabilities: Option<Vec<String>>,
122        limit: Option<usize>,
123    ) -> RedDBResult<DslQueryResult> {
124        RedDBRuntime::search_index(
125            self,
126            index,
127            value,
128            exact,
129            collections,
130            entity_types,
131            capabilities,
132            limit,
133        )
134    }
135
136    fn search_context(
137        &self,
138        input: crate::application::SearchContextInput,
139    ) -> RedDBResult<crate::runtime::ContextSearchResult> {
140        RedDBRuntime::search_context(self, input)
141    }
142
143    fn resolve_semantic_api_key(&self, provider: &crate::ai::AiProvider) -> RedDBResult<String> {
144        crate::ai::resolve_api_key_from_runtime(provider, None, self)
145    }
146}