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
16pub mod file_upload;
18pub use file_upload::*;
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
25#[serde(rename_all = "snake_case")]
26pub enum ReadPreference {
27 Master,
29 #[default]
31 Replica,
32 Nearest,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct HostConfig {
39 pub master: String,
41 pub replicas: Vec<String>,
43}
44
45#[derive(Debug, Clone, Default)]
47pub struct ReadOptions {
48 pub read_preference: Option<ReadPreference>,
50}
51
52#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
54#[serde(rename_all = "snake_case")]
55pub enum SimilarityMetric {
56 #[default]
58 Cosine,
59 Euclidean,
61 DotProduct,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct Vector {
68 pub id: String,
70 pub data: Vec<f32>,
72 pub metadata: Option<HashMap<String, serde_json::Value>>,
74 #[serde(skip_serializing_if = "Option::is_none")]
76 pub public_key: Option<String>,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct Collection {
82 pub name: String,
84 pub dimension: usize,
86 #[serde(alias = "similarity_metric")]
88 pub metric: Option<String>,
89 #[serde(default)]
91 pub description: Option<String>,
92 #[serde(default)]
94 pub created_at: Option<String>,
95 #[serde(default)]
97 pub updated_at: Option<String>,
98 #[serde(default)]
100 pub vector_count: usize,
101 #[serde(default)]
103 pub document_count: usize,
104 #[serde(default)]
106 pub embedding_provider: Option<String>,
107 #[serde(default)]
109 pub indexing_status: Option<serde_json::Value>,
110 #[serde(default)]
112 pub normalization: Option<serde_json::Value>,
113 #[serde(default)]
115 pub quantization: Option<serde_json::Value>,
116 #[serde(default)]
118 pub size: Option<serde_json::Value>,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct CollectionInfo {
124 pub name: String,
126 pub dimension: usize,
128 pub metric: String,
130 #[serde(default)]
132 pub vector_count: usize,
133 #[serde(default)]
135 pub document_count: usize,
136 pub created_at: String,
138 pub updated_at: String,
140 #[serde(default)]
142 pub indexing_status: Option<IndexingStatus>,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
147pub struct IndexingStatus {
148 pub status: String,
150 pub progress: f32,
152 pub total_documents: usize,
154 pub processed_documents: usize,
156 pub vector_count: usize,
158 pub estimated_time_remaining: Option<String>,
160 pub last_updated: String,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize)]
166pub struct SearchResult {
167 pub id: String,
169 pub score: f32,
171 pub content: Option<String>,
173 pub metadata: Option<HashMap<String, serde_json::Value>>,
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize)]
179pub struct SearchResponse {
180 pub results: Vec<SearchResult>,
182 pub query_time_ms: f64,
184}
185
186#[derive(Debug, Clone, Serialize, Deserialize)]
188pub struct EmbeddingRequest {
189 pub text: String,
191 pub model: Option<String>,
193 pub parameters: Option<EmbeddingParameters>,
195}
196
197#[derive(Debug, Clone, Serialize, Deserialize)]
199pub struct EmbeddingParameters {
200 pub max_length: Option<usize>,
202 pub normalize: Option<bool>,
204 pub prefix: Option<String>,
206}
207
208#[derive(Debug, Clone, Serialize, Deserialize)]
210pub struct EmbeddingResponse {
211 pub embedding: Vec<f32>,
213 pub model: String,
215 pub text: String,
217 pub dimension: usize,
219 pub provider: String,
221}
222
223#[derive(Debug, Clone, Serialize, Deserialize)]
225pub struct HealthStatus {
226 pub status: String,
228 pub version: String,
230 pub timestamp: String,
232 pub uptime: Option<u64>,
234 pub collections: Option<usize>,
236 pub total_vectors: Option<usize>,
238}
239
240#[derive(Debug, Clone, Serialize, Deserialize)]
242pub struct CollectionsResponse {
243 pub collections: Vec<Collection>,
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize)]
249pub struct CreateCollectionResponse {
250 pub message: String,
252 pub collection: String,
254}
255
256#[derive(Debug, Clone, Serialize, Deserialize)]
258pub struct DatabaseStats {
259 pub total_collections: usize,
261 pub total_vectors: usize,
263 pub total_memory_estimate_bytes: usize,
265 pub collections: Vec<CollectionStats>,
267}
268
269#[derive(Debug, Clone, Serialize, Deserialize)]
271pub struct CollectionStats {
272 pub name: String,
274 pub vector_count: usize,
276 pub dimension: usize,
278 pub memory_estimate_bytes: usize,
280}
281
282#[derive(Debug, Clone, Serialize, Deserialize)]
284pub struct BatchTextRequest {
285 pub id: String,
287 pub text: String,
289 pub metadata: Option<HashMap<String, String>>,
291}
292
293#[derive(Debug, Clone, Serialize, Deserialize)]
295pub struct BatchConfig {
296 pub max_batch_size: Option<usize>,
298 pub parallel_workers: Option<usize>,
300 pub atomic: Option<bool>,
302}
303
304#[derive(Debug, Clone, Serialize, Deserialize)]
306pub struct BatchInsertRequest {
307 pub texts: Vec<BatchTextRequest>,
309 pub config: Option<BatchConfig>,
311}
312
313#[derive(Debug, Clone, Serialize, Deserialize)]
315pub struct BatchResponse {
316 pub success: bool,
318 pub collection: String,
320 pub operation: String,
322 pub total_operations: usize,
324 pub successful_operations: usize,
326 pub failed_operations: usize,
328 pub duration_ms: u64,
330 pub errors: Vec<String>,
332}
333
334#[derive(Debug, Clone, Serialize, Deserialize)]
336pub struct BatchSearchQuery {
337 pub query: String,
339 pub limit: Option<usize>,
341 pub score_threshold: Option<f32>,
343}
344
345#[derive(Debug, Clone, Serialize, Deserialize)]
347pub struct BatchSearchRequest {
348 pub queries: Vec<BatchSearchQuery>,
350 pub config: Option<BatchConfig>,
352}
353
354#[derive(Debug, Clone, Serialize, Deserialize)]
356pub struct BatchSearchResponse {
357 pub success: bool,
359 pub collection: String,
361 pub total_queries: usize,
363 pub successful_queries: usize,
365 pub failed_queries: usize,
367 pub duration_ms: u64,
369 pub results: Vec<Vec<SearchResult>>,
371 pub errors: Vec<String>,
373}
374
375#[derive(Debug, Clone, Serialize, Deserialize)]
377pub struct BatchVectorUpdate {
378 pub id: String,
380 pub data: Option<Vec<f32>>,
382 pub metadata: Option<HashMap<String, serde_json::Value>>,
384}
385
386#[derive(Debug, Clone, Serialize, Deserialize)]
388pub struct BatchUpdateRequest {
389 pub updates: Vec<BatchVectorUpdate>,
391 pub config: Option<BatchConfig>,
393}
394
395#[derive(Debug, Clone, Serialize, Deserialize)]
397pub struct BatchDeleteRequest {
398 pub vector_ids: Vec<String>,
400 pub config: Option<BatchConfig>,
402}
403
404#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
406#[serde(rename_all = "snake_case")]
407pub enum SummarizationMethod {
408 #[default]
410 Extractive,
411 Keyword,
413 Sentence,
415 Abstractive,
417}
418
419#[derive(Debug, Clone, Serialize, Deserialize)]
421pub struct SummarizeTextRequest {
422 pub text: String,
424 pub method: Option<SummarizationMethod>,
426 pub max_length: Option<usize>,
428 pub compression_ratio: Option<f32>,
430 pub language: Option<String>,
432}
433
434#[derive(Debug, Clone, Serialize, Deserialize)]
436pub struct SummarizeTextResponse {
437 pub summary_id: String,
439 pub original_text: String,
441 pub summary: String,
443 pub method: String,
445 pub original_length: usize,
447 pub summary_length: usize,
449 pub compression_ratio: f32,
451 pub language: String,
453 pub status: String,
455 pub message: String,
457 pub metadata: HashMap<String, String>,
459}
460
461#[derive(Debug, Clone, Serialize, Deserialize)]
463pub struct SummarizeContextRequest {
464 pub context: String,
466 pub method: Option<SummarizationMethod>,
468 pub max_length: Option<usize>,
470 pub compression_ratio: Option<f32>,
472 pub language: Option<String>,
474}
475
476#[derive(Debug, Clone, Serialize, Deserialize)]
478pub struct SummarizeContextResponse {
479 pub summary_id: String,
481 pub original_context: String,
483 pub summary: String,
485 pub method: String,
487 pub original_length: usize,
489 pub summary_length: usize,
491 pub compression_ratio: f32,
493 pub language: String,
495 pub status: String,
497 pub message: String,
499 pub metadata: HashMap<String, String>,
501}
502
503#[derive(Debug, Clone, Serialize, Deserialize)]
505pub struct GetSummaryResponse {
506 pub summary_id: String,
508 pub original_text: String,
510 pub summary: String,
512 pub method: String,
514 pub original_length: usize,
516 pub summary_length: usize,
518 pub compression_ratio: f32,
520 pub language: String,
522 pub created_at: String,
524 pub metadata: HashMap<String, String>,
526 pub status: String,
528}
529
530#[derive(Debug, Clone, Serialize, Deserialize)]
532pub struct SummaryInfo {
533 pub summary_id: String,
535 pub method: String,
537 pub language: String,
539 pub original_length: usize,
541 pub summary_length: usize,
543 pub compression_ratio: f32,
545 pub created_at: String,
547 pub metadata: HashMap<String, String>,
549}
550
551#[derive(Debug, Clone, Serialize, Deserialize)]
553pub struct ListSummariesResponse {
554 pub summaries: Vec<SummaryInfo>,
556 pub total_count: usize,
558 pub status: String,
560}
561
562#[derive(Debug, Clone, Serialize, Deserialize)]
564pub struct IndexingProgress {
565 pub is_indexing: bool,
567 pub overall_status: String,
569 pub collections: Vec<CollectionProgress>,
571}
572
573#[derive(Debug, Clone, Serialize, Deserialize)]
575pub struct CollectionProgress {
576 pub collection_name: String,
578 pub status: String,
580 pub progress: f32,
582 pub vector_count: usize,
584 pub error_message: Option<String>,
586 pub last_updated: String,
588}
589
590#[derive(Debug, Clone, Serialize, Deserialize)]
594pub struct IntelligentSearchRequest {
595 pub query: String,
597 pub collections: Option<Vec<String>>,
599 pub max_results: Option<usize>,
601 pub domain_expansion: Option<bool>,
603 pub technical_focus: Option<bool>,
605 pub mmr_enabled: Option<bool>,
607 pub mmr_lambda: Option<f32>,
609}
610
611#[derive(Debug, Clone, Serialize, Deserialize)]
613pub struct SemanticSearchRequest {
614 pub query: String,
616 pub collection: String,
618 pub max_results: Option<usize>,
620 pub semantic_reranking: Option<bool>,
622 pub cross_encoder_reranking: Option<bool>,
624 pub similarity_threshold: Option<f32>,
626}
627
628#[derive(Debug, Clone, Serialize, Deserialize)]
630pub struct ContextualSearchRequest {
631 pub query: String,
633 pub collection: String,
635 pub context_filters: Option<HashMap<String, serde_json::Value>>,
637 pub max_results: Option<usize>,
639 pub context_reranking: Option<bool>,
641 pub context_weight: Option<f32>,
643}
644
645#[derive(Debug, Clone, Serialize, Deserialize)]
647pub struct MultiCollectionSearchRequest {
648 pub query: String,
650 pub collections: Vec<String>,
652 pub max_per_collection: Option<usize>,
654 pub max_total_results: Option<usize>,
656 pub cross_collection_reranking: Option<bool>,
658}
659
660#[derive(Debug, Clone, Serialize, Deserialize)]
662pub struct IntelligentSearchResult {
663 pub id: String,
665 pub score: f32,
667 pub content: String,
669 pub metadata: Option<HashMap<String, serde_json::Value>>,
671 pub collection: Option<String>,
673 pub query_used: Option<String>,
675}
676
677#[derive(Debug, Clone, Serialize, Deserialize)]
679pub struct IntelligentSearchResponse {
680 pub results: Vec<IntelligentSearchResult>,
682 pub total_results: usize,
684 pub duration_ms: u64,
686 pub queries_generated: Option<Vec<String>>,
688 pub collections_searched: Option<Vec<String>>,
690 pub metadata: Option<HashMap<String, serde_json::Value>>,
692}
693
694#[derive(Debug, Clone, Serialize, Deserialize)]
696pub struct SemanticSearchResponse {
697 pub results: Vec<IntelligentSearchResult>,
699 pub total_results: usize,
701 pub duration_ms: u64,
703 pub collection: String,
705 pub metadata: Option<HashMap<String, serde_json::Value>>,
707}
708
709#[derive(Debug, Clone, Serialize, Deserialize)]
711pub struct ContextualSearchResponse {
712 pub results: Vec<IntelligentSearchResult>,
714 pub total_results: usize,
716 pub duration_ms: u64,
718 pub collection: String,
720 pub context_filters: Option<HashMap<String, serde_json::Value>>,
722 pub metadata: Option<HashMap<String, serde_json::Value>>,
724}
725
726#[derive(Debug, Clone, Serialize, Deserialize)]
728pub struct MultiCollectionSearchResponse {
729 pub results: Vec<IntelligentSearchResult>,
731 pub total_results: usize,
733 pub duration_ms: u64,
735 pub collections_searched: Vec<String>,
737 pub results_per_collection: Option<HashMap<String, usize>>,
739 pub metadata: Option<HashMap<String, serde_json::Value>>,
741}
742
743#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
747#[serde(rename_all = "PascalCase")]
748pub enum ReplicaStatus {
749 Connected,
751 Syncing,
753 Lagging,
755 Disconnected,
757}
758
759#[derive(Debug, Clone, Serialize, Deserialize)]
761pub struct ReplicaInfo {
762 pub replica_id: String,
764 pub host: String,
766 pub port: u16,
768 pub status: String,
770 pub last_heartbeat: DateTime<Utc>,
772 pub operations_synced: u64,
774
775 #[serde(skip_serializing_if = "Option::is_none")]
778 pub offset: Option<u64>,
779 #[serde(skip_serializing_if = "Option::is_none")]
781 pub lag: Option<u64>,
782}
783
784#[derive(Debug, Clone, Serialize, Deserialize)]
786pub struct ReplicationStats {
787 #[serde(skip_serializing_if = "Option::is_none")]
790 pub role: Option<String>,
791 #[serde(skip_serializing_if = "Option::is_none")]
793 pub bytes_sent: Option<u64>,
794 #[serde(skip_serializing_if = "Option::is_none")]
796 pub bytes_received: Option<u64>,
797 #[serde(skip_serializing_if = "Option::is_none")]
799 pub last_sync: Option<DateTime<Utc>>,
800 #[serde(skip_serializing_if = "Option::is_none")]
802 pub operations_pending: Option<usize>,
803 #[serde(skip_serializing_if = "Option::is_none")]
805 pub snapshot_size: Option<usize>,
806 #[serde(skip_serializing_if = "Option::is_none")]
808 pub connected_replicas: Option<usize>,
809
810 pub master_offset: u64,
813 pub replica_offset: u64,
815 pub lag_operations: u64,
817 pub total_replicated: u64,
819}
820
821#[derive(Debug, Clone, Serialize, Deserialize)]
823pub struct ReplicationStatusResponse {
824 pub status: String,
826 pub stats: ReplicationStats,
828 #[serde(skip_serializing_if = "Option::is_none")]
830 pub message: Option<String>,
831}
832
833#[derive(Debug, Clone, Serialize, Deserialize)]
835pub struct ReplicaListResponse {
836 pub replicas: Vec<ReplicaInfo>,
838 pub count: usize,
840 pub message: String,
842}