1use std::collections::HashMap;
4
5use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7
8pub mod hybrid_search;
10pub use hybrid_search::*;
11
12pub mod graph;
14pub use graph::*;
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
21#[serde(rename_all = "snake_case")]
22pub enum ReadPreference {
23 Master,
25 #[default]
27 Replica,
28 Nearest,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct HostConfig {
35 pub master: String,
37 pub replicas: Vec<String>,
39}
40
41#[derive(Debug, Clone, Default)]
43pub struct ReadOptions {
44 pub read_preference: Option<ReadPreference>,
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
50#[serde(rename_all = "snake_case")]
51pub enum SimilarityMetric {
52 #[default]
54 Cosine,
55 Euclidean,
57 DotProduct,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct Vector {
64 pub id: String,
66 pub data: Vec<f32>,
68 pub metadata: Option<HashMap<String, serde_json::Value>>,
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct Collection {
75 pub name: String,
77 pub dimension: usize,
79 #[serde(alias = "similarity_metric")]
81 pub metric: Option<String>,
82 #[serde(default)]
84 pub description: Option<String>,
85 #[serde(default)]
87 pub created_at: Option<String>,
88 #[serde(default)]
90 pub updated_at: Option<String>,
91 #[serde(default)]
93 pub vector_count: usize,
94 #[serde(default)]
96 pub document_count: usize,
97 #[serde(default)]
99 pub embedding_provider: Option<String>,
100 #[serde(default)]
102 pub indexing_status: Option<serde_json::Value>,
103 #[serde(default)]
105 pub normalization: Option<serde_json::Value>,
106 #[serde(default)]
108 pub quantization: Option<serde_json::Value>,
109 #[serde(default)]
111 pub size: Option<serde_json::Value>,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
116pub struct CollectionInfo {
117 pub name: String,
119 pub dimension: usize,
121 pub metric: String,
123 #[serde(default)]
125 pub vector_count: usize,
126 #[serde(default)]
128 pub document_count: usize,
129 pub created_at: String,
131 pub updated_at: String,
133 #[serde(default)]
135 pub indexing_status: Option<IndexingStatus>,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct IndexingStatus {
141 pub status: String,
143 pub progress: f32,
145 pub total_documents: usize,
147 pub processed_documents: usize,
149 pub vector_count: usize,
151 pub estimated_time_remaining: Option<String>,
153 pub last_updated: String,
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct SearchResult {
160 pub id: String,
162 pub score: f32,
164 pub content: Option<String>,
166 pub metadata: Option<HashMap<String, serde_json::Value>>,
168}
169
170#[derive(Debug, Clone, Serialize, Deserialize)]
172pub struct SearchResponse {
173 pub results: Vec<SearchResult>,
175 pub query_time_ms: f64,
177}
178
179#[derive(Debug, Clone, Serialize, Deserialize)]
181pub struct EmbeddingRequest {
182 pub text: String,
184 pub model: Option<String>,
186 pub parameters: Option<EmbeddingParameters>,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
192pub struct EmbeddingParameters {
193 pub max_length: Option<usize>,
195 pub normalize: Option<bool>,
197 pub prefix: Option<String>,
199}
200
201#[derive(Debug, Clone, Serialize, Deserialize)]
203pub struct EmbeddingResponse {
204 pub embedding: Vec<f32>,
206 pub model: String,
208 pub text: String,
210 pub dimension: usize,
212 pub provider: String,
214}
215
216#[derive(Debug, Clone, Serialize, Deserialize)]
218pub struct HealthStatus {
219 pub status: String,
221 pub version: String,
223 pub timestamp: String,
225 pub uptime: Option<u64>,
227 pub collections: Option<usize>,
229 pub total_vectors: Option<usize>,
231}
232
233#[derive(Debug, Clone, Serialize, Deserialize)]
235pub struct CollectionsResponse {
236 pub collections: Vec<Collection>,
238}
239
240#[derive(Debug, Clone, Serialize, Deserialize)]
242pub struct CreateCollectionResponse {
243 pub message: String,
245 pub collection: String,
247}
248
249#[derive(Debug, Clone, Serialize, Deserialize)]
251pub struct DatabaseStats {
252 pub total_collections: usize,
254 pub total_vectors: usize,
256 pub total_memory_estimate_bytes: usize,
258 pub collections: Vec<CollectionStats>,
260}
261
262#[derive(Debug, Clone, Serialize, Deserialize)]
264pub struct CollectionStats {
265 pub name: String,
267 pub vector_count: usize,
269 pub dimension: usize,
271 pub memory_estimate_bytes: usize,
273}
274
275#[derive(Debug, Clone, Serialize, Deserialize)]
277pub struct BatchTextRequest {
278 pub id: String,
280 pub text: String,
282 pub metadata: Option<HashMap<String, String>>,
284}
285
286#[derive(Debug, Clone, Serialize, Deserialize)]
288pub struct BatchConfig {
289 pub max_batch_size: Option<usize>,
291 pub parallel_workers: Option<usize>,
293 pub atomic: Option<bool>,
295}
296
297#[derive(Debug, Clone, Serialize, Deserialize)]
299pub struct BatchInsertRequest {
300 pub texts: Vec<BatchTextRequest>,
302 pub config: Option<BatchConfig>,
304}
305
306#[derive(Debug, Clone, Serialize, Deserialize)]
308pub struct BatchResponse {
309 pub success: bool,
311 pub collection: String,
313 pub operation: String,
315 pub total_operations: usize,
317 pub successful_operations: usize,
319 pub failed_operations: usize,
321 pub duration_ms: u64,
323 pub errors: Vec<String>,
325}
326
327#[derive(Debug, Clone, Serialize, Deserialize)]
329pub struct BatchSearchQuery {
330 pub query: String,
332 pub limit: Option<usize>,
334 pub score_threshold: Option<f32>,
336}
337
338#[derive(Debug, Clone, Serialize, Deserialize)]
340pub struct BatchSearchRequest {
341 pub queries: Vec<BatchSearchQuery>,
343 pub config: Option<BatchConfig>,
345}
346
347#[derive(Debug, Clone, Serialize, Deserialize)]
349pub struct BatchSearchResponse {
350 pub success: bool,
352 pub collection: String,
354 pub total_queries: usize,
356 pub successful_queries: usize,
358 pub failed_queries: usize,
360 pub duration_ms: u64,
362 pub results: Vec<Vec<SearchResult>>,
364 pub errors: Vec<String>,
366}
367
368#[derive(Debug, Clone, Serialize, Deserialize)]
370pub struct BatchVectorUpdate {
371 pub id: String,
373 pub data: Option<Vec<f32>>,
375 pub metadata: Option<HashMap<String, serde_json::Value>>,
377}
378
379#[derive(Debug, Clone, Serialize, Deserialize)]
381pub struct BatchUpdateRequest {
382 pub updates: Vec<BatchVectorUpdate>,
384 pub config: Option<BatchConfig>,
386}
387
388#[derive(Debug, Clone, Serialize, Deserialize)]
390pub struct BatchDeleteRequest {
391 pub vector_ids: Vec<String>,
393 pub config: Option<BatchConfig>,
395}
396
397#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
399#[serde(rename_all = "snake_case")]
400pub enum SummarizationMethod {
401 #[default]
403 Extractive,
404 Keyword,
406 Sentence,
408 Abstractive,
410}
411
412#[derive(Debug, Clone, Serialize, Deserialize)]
414pub struct SummarizeTextRequest {
415 pub text: String,
417 pub method: Option<SummarizationMethod>,
419 pub max_length: Option<usize>,
421 pub compression_ratio: Option<f32>,
423 pub language: Option<String>,
425}
426
427#[derive(Debug, Clone, Serialize, Deserialize)]
429pub struct SummarizeTextResponse {
430 pub summary_id: String,
432 pub original_text: String,
434 pub summary: String,
436 pub method: String,
438 pub original_length: usize,
440 pub summary_length: usize,
442 pub compression_ratio: f32,
444 pub language: String,
446 pub status: String,
448 pub message: String,
450 pub metadata: HashMap<String, String>,
452}
453
454#[derive(Debug, Clone, Serialize, Deserialize)]
456pub struct SummarizeContextRequest {
457 pub context: String,
459 pub method: Option<SummarizationMethod>,
461 pub max_length: Option<usize>,
463 pub compression_ratio: Option<f32>,
465 pub language: Option<String>,
467}
468
469#[derive(Debug, Clone, Serialize, Deserialize)]
471pub struct SummarizeContextResponse {
472 pub summary_id: String,
474 pub original_context: String,
476 pub summary: String,
478 pub method: String,
480 pub original_length: usize,
482 pub summary_length: usize,
484 pub compression_ratio: f32,
486 pub language: String,
488 pub status: String,
490 pub message: String,
492 pub metadata: HashMap<String, String>,
494}
495
496#[derive(Debug, Clone, Serialize, Deserialize)]
498pub struct GetSummaryResponse {
499 pub summary_id: String,
501 pub original_text: String,
503 pub summary: String,
505 pub method: String,
507 pub original_length: usize,
509 pub summary_length: usize,
511 pub compression_ratio: f32,
513 pub language: String,
515 pub created_at: String,
517 pub metadata: HashMap<String, String>,
519 pub status: String,
521}
522
523#[derive(Debug, Clone, Serialize, Deserialize)]
525pub struct SummaryInfo {
526 pub summary_id: String,
528 pub method: String,
530 pub language: String,
532 pub original_length: usize,
534 pub summary_length: usize,
536 pub compression_ratio: f32,
538 pub created_at: String,
540 pub metadata: HashMap<String, String>,
542}
543
544#[derive(Debug, Clone, Serialize, Deserialize)]
546pub struct ListSummariesResponse {
547 pub summaries: Vec<SummaryInfo>,
549 pub total_count: usize,
551 pub status: String,
553}
554
555#[derive(Debug, Clone, Serialize, Deserialize)]
557pub struct IndexingProgress {
558 pub is_indexing: bool,
560 pub overall_status: String,
562 pub collections: Vec<CollectionProgress>,
564}
565
566#[derive(Debug, Clone, Serialize, Deserialize)]
568pub struct CollectionProgress {
569 pub collection_name: String,
571 pub status: String,
573 pub progress: f32,
575 pub vector_count: usize,
577 pub error_message: Option<String>,
579 pub last_updated: String,
581}
582
583#[derive(Debug, Clone, Serialize, Deserialize)]
587pub struct IntelligentSearchRequest {
588 pub query: String,
590 pub collections: Option<Vec<String>>,
592 pub max_results: Option<usize>,
594 pub domain_expansion: Option<bool>,
596 pub technical_focus: Option<bool>,
598 pub mmr_enabled: Option<bool>,
600 pub mmr_lambda: Option<f32>,
602}
603
604#[derive(Debug, Clone, Serialize, Deserialize)]
606pub struct SemanticSearchRequest {
607 pub query: String,
609 pub collection: String,
611 pub max_results: Option<usize>,
613 pub semantic_reranking: Option<bool>,
615 pub cross_encoder_reranking: Option<bool>,
617 pub similarity_threshold: Option<f32>,
619}
620
621#[derive(Debug, Clone, Serialize, Deserialize)]
623pub struct ContextualSearchRequest {
624 pub query: String,
626 pub collection: String,
628 pub context_filters: Option<HashMap<String, serde_json::Value>>,
630 pub max_results: Option<usize>,
632 pub context_reranking: Option<bool>,
634 pub context_weight: Option<f32>,
636}
637
638#[derive(Debug, Clone, Serialize, Deserialize)]
640pub struct MultiCollectionSearchRequest {
641 pub query: String,
643 pub collections: Vec<String>,
645 pub max_per_collection: Option<usize>,
647 pub max_total_results: Option<usize>,
649 pub cross_collection_reranking: Option<bool>,
651}
652
653#[derive(Debug, Clone, Serialize, Deserialize)]
655pub struct IntelligentSearchResult {
656 pub id: String,
658 pub score: f32,
660 pub content: String,
662 pub metadata: Option<HashMap<String, serde_json::Value>>,
664 pub collection: Option<String>,
666 pub query_used: Option<String>,
668}
669
670#[derive(Debug, Clone, Serialize, Deserialize)]
672pub struct IntelligentSearchResponse {
673 pub results: Vec<IntelligentSearchResult>,
675 pub total_results: usize,
677 pub duration_ms: u64,
679 pub queries_generated: Option<Vec<String>>,
681 pub collections_searched: Option<Vec<String>>,
683 pub metadata: Option<HashMap<String, serde_json::Value>>,
685}
686
687#[derive(Debug, Clone, Serialize, Deserialize)]
689pub struct SemanticSearchResponse {
690 pub results: Vec<IntelligentSearchResult>,
692 pub total_results: usize,
694 pub duration_ms: u64,
696 pub collection: String,
698 pub metadata: Option<HashMap<String, serde_json::Value>>,
700}
701
702#[derive(Debug, Clone, Serialize, Deserialize)]
704pub struct ContextualSearchResponse {
705 pub results: Vec<IntelligentSearchResult>,
707 pub total_results: usize,
709 pub duration_ms: u64,
711 pub collection: String,
713 pub context_filters: Option<HashMap<String, serde_json::Value>>,
715 pub metadata: Option<HashMap<String, serde_json::Value>>,
717}
718
719#[derive(Debug, Clone, Serialize, Deserialize)]
721pub struct MultiCollectionSearchResponse {
722 pub results: Vec<IntelligentSearchResult>,
724 pub total_results: usize,
726 pub duration_ms: u64,
728 pub collections_searched: Vec<String>,
730 pub results_per_collection: Option<HashMap<String, usize>>,
732 pub metadata: Option<HashMap<String, serde_json::Value>>,
734}
735
736#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
740#[serde(rename_all = "PascalCase")]
741pub enum ReplicaStatus {
742 Connected,
744 Syncing,
746 Lagging,
748 Disconnected,
750}
751
752#[derive(Debug, Clone, Serialize, Deserialize)]
754pub struct ReplicaInfo {
755 pub replica_id: String,
757 pub host: String,
759 pub port: u16,
761 pub status: String,
763 pub last_heartbeat: DateTime<Utc>,
765 pub operations_synced: u64,
767
768 #[serde(skip_serializing_if = "Option::is_none")]
771 pub offset: Option<u64>,
772 #[serde(skip_serializing_if = "Option::is_none")]
774 pub lag: Option<u64>,
775}
776
777#[derive(Debug, Clone, Serialize, Deserialize)]
779pub struct ReplicationStats {
780 #[serde(skip_serializing_if = "Option::is_none")]
783 pub role: Option<String>,
784 #[serde(skip_serializing_if = "Option::is_none")]
786 pub bytes_sent: Option<u64>,
787 #[serde(skip_serializing_if = "Option::is_none")]
789 pub bytes_received: Option<u64>,
790 #[serde(skip_serializing_if = "Option::is_none")]
792 pub last_sync: Option<DateTime<Utc>>,
793 #[serde(skip_serializing_if = "Option::is_none")]
795 pub operations_pending: Option<usize>,
796 #[serde(skip_serializing_if = "Option::is_none")]
798 pub snapshot_size: Option<usize>,
799 #[serde(skip_serializing_if = "Option::is_none")]
801 pub connected_replicas: Option<usize>,
802
803 pub master_offset: u64,
806 pub replica_offset: u64,
808 pub lag_operations: u64,
810 pub total_replicated: u64,
812}
813
814#[derive(Debug, Clone, Serialize, Deserialize)]
816pub struct ReplicationStatusResponse {
817 pub status: String,
819 pub stats: ReplicationStats,
821 #[serde(skip_serializing_if = "Option::is_none")]
823 pub message: Option<String>,
824}
825
826#[derive(Debug, Clone, Serialize, Deserialize)]
828pub struct ReplicaListResponse {
829 pub replicas: Vec<ReplicaInfo>,
831 pub count: usize,
833 pub message: String,
835}