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)]
130pub struct CollectionInfo {
131 pub name: String,
133 pub dimension: usize,
135 #[serde(default, alias = "similarity_metric")]
140 pub metric: String,
141 #[serde(default)]
143 pub vector_count: usize,
144 #[serde(default)]
146 pub document_count: usize,
147 #[serde(default)]
149 pub created_at: String,
150 #[serde(default)]
152 pub updated_at: String,
153 #[serde(default)]
155 pub indexing_status: Option<IndexingStatus>,
156 #[serde(default)]
159 pub size: Option<serde_json::Value>,
160 #[serde(default)]
162 pub quantization: Option<serde_json::Value>,
163 #[serde(default)]
165 pub normalization: Option<serde_json::Value>,
166 #[serde(default)]
168 pub status: Option<String>,
169}
170
171#[derive(Debug, Clone, Serialize, Deserialize)]
173pub struct IndexingStatus {
174 pub status: String,
176 pub progress: f32,
178 pub total_documents: usize,
180 pub processed_documents: usize,
182 pub vector_count: usize,
184 pub estimated_time_remaining: Option<String>,
186 pub last_updated: String,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
192pub struct SearchResult {
193 pub id: String,
195 pub score: f32,
197 pub content: Option<String>,
199 pub metadata: Option<HashMap<String, serde_json::Value>>,
201}
202
203#[derive(Debug, Clone, Serialize, Deserialize)]
210pub struct SearchResponse {
211 #[serde(default)]
213 pub results: Vec<SearchResult>,
214 #[serde(default)]
217 pub query_time_ms: f64,
218 #[serde(default)]
220 pub query: Option<String>,
221 #[serde(default)]
223 pub limit: Option<usize>,
224 #[serde(default)]
226 pub collection: Option<String>,
227}
228
229#[derive(Debug, Clone, Serialize, Deserialize)]
231pub struct EmbeddingRequest {
232 pub text: String,
234 pub model: Option<String>,
236 pub parameters: Option<EmbeddingParameters>,
238}
239
240#[derive(Debug, Clone, Serialize, Deserialize)]
242pub struct EmbeddingParameters {
243 pub max_length: Option<usize>,
245 pub normalize: Option<bool>,
247 pub prefix: Option<String>,
249}
250
251#[derive(Debug, Clone, Serialize, Deserialize)]
253pub struct EmbeddingResponse {
254 pub embedding: Vec<f32>,
256 pub model: String,
258 pub text: String,
260 pub dimension: usize,
262 pub provider: String,
264}
265
266#[derive(Debug, Clone, Serialize, Deserialize)]
268pub struct HealthStatus {
269 pub status: String,
271 pub version: String,
273 pub timestamp: String,
275 pub uptime: Option<u64>,
277 pub collections: Option<usize>,
279 pub total_vectors: Option<usize>,
281}
282
283#[derive(Debug, Clone, Serialize, Deserialize)]
285pub struct CollectionsResponse {
286 pub collections: Vec<Collection>,
288}
289
290#[derive(Debug, Clone, Serialize, Deserialize)]
292pub struct CreateCollectionResponse {
293 pub message: String,
295 pub collection: String,
297}
298
299#[derive(Debug, Clone, Serialize, Deserialize)]
301pub struct DatabaseStats {
302 pub total_collections: usize,
304 pub total_vectors: usize,
306 pub total_memory_estimate_bytes: usize,
308 pub collections: Vec<CollectionStats>,
310}
311
312#[derive(Debug, Clone, Serialize, Deserialize)]
314pub struct CollectionStats {
315 pub name: String,
317 pub vector_count: usize,
319 pub dimension: usize,
321 pub memory_estimate_bytes: usize,
323}
324
325#[derive(Debug, Clone, Serialize, Deserialize)]
327pub struct BatchTextRequest {
328 pub id: String,
330 pub text: String,
332 pub metadata: Option<HashMap<String, String>>,
334}
335
336#[derive(Debug, Clone, Serialize, Deserialize)]
338pub struct BatchConfig {
339 pub max_batch_size: Option<usize>,
341 pub parallel_workers: Option<usize>,
343 pub atomic: Option<bool>,
345}
346
347#[derive(Debug, Clone, Serialize, Deserialize)]
349pub struct BatchInsertRequest {
350 pub texts: Vec<BatchTextRequest>,
352 pub config: Option<BatchConfig>,
354}
355
356#[derive(Debug, Clone, Serialize, Deserialize)]
365pub struct BatchResponse {
366 #[serde(default)]
370 pub success: bool,
371 #[serde(default)]
373 pub collection: String,
374 #[serde(default)]
376 pub operation: String,
377 #[serde(default, alias = "count")]
380 pub total_operations: usize,
381 #[serde(default, alias = "inserted")]
384 pub successful_operations: usize,
385 #[serde(default, alias = "failed")]
387 pub failed_operations: usize,
388 #[serde(default)]
390 pub duration_ms: u64,
391 #[serde(default)]
393 pub errors: Vec<String>,
394 #[serde(default)]
399 pub results: Vec<BatchResultEntry>,
400}
401
402#[derive(Debug, Clone, Serialize, Deserialize)]
407pub struct BatchResultEntry {
408 #[serde(default)]
410 pub client_id: String,
411 #[serde(default)]
413 pub index: usize,
414 #[serde(default)]
416 pub status: String,
417 #[serde(default)]
420 pub chunked: bool,
421 #[serde(default)]
423 pub vector_ids: Vec<String>,
424 #[serde(default)]
426 pub vectors_created: usize,
427 #[serde(default)]
429 pub error: Option<String>,
430}
431
432#[derive(Debug, Clone, Serialize, Deserialize)]
434pub struct BatchSearchQuery {
435 pub query: String,
437 pub limit: Option<usize>,
439 pub score_threshold: Option<f32>,
441}
442
443#[derive(Debug, Clone, Serialize, Deserialize)]
445pub struct BatchSearchRequest {
446 pub queries: Vec<BatchSearchQuery>,
448 pub config: Option<BatchConfig>,
450}
451
452#[derive(Debug, Clone, Serialize, Deserialize)]
454pub struct BatchSearchResponse {
455 pub success: bool,
457 pub collection: String,
459 pub total_queries: usize,
461 pub successful_queries: usize,
463 pub failed_queries: usize,
465 pub duration_ms: u64,
467 pub results: Vec<Vec<SearchResult>>,
469 pub errors: Vec<String>,
471}
472
473#[derive(Debug, Clone, Serialize, Deserialize)]
475pub struct BatchVectorUpdate {
476 pub id: String,
478 pub data: Option<Vec<f32>>,
480 pub metadata: Option<HashMap<String, serde_json::Value>>,
482}
483
484#[derive(Debug, Clone, Serialize, Deserialize)]
486pub struct BatchUpdateRequest {
487 pub updates: Vec<BatchVectorUpdate>,
489 pub config: Option<BatchConfig>,
491}
492
493#[derive(Debug, Clone, Serialize, Deserialize)]
495pub struct BatchDeleteRequest {
496 pub vector_ids: Vec<String>,
498 pub config: Option<BatchConfig>,
500}
501
502#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
504#[serde(rename_all = "snake_case")]
505pub enum SummarizationMethod {
506 #[default]
508 Extractive,
509 Keyword,
511 Sentence,
513 Abstractive,
515}
516
517#[derive(Debug, Clone, Serialize, Deserialize)]
519pub struct SummarizeTextRequest {
520 pub text: String,
522 pub method: Option<SummarizationMethod>,
524 pub max_length: Option<usize>,
526 pub compression_ratio: Option<f32>,
528 pub language: Option<String>,
530}
531
532#[derive(Debug, Clone, Serialize, Deserialize)]
534pub struct SummarizeTextResponse {
535 pub summary_id: String,
537 pub original_text: String,
539 pub summary: String,
541 pub method: String,
543 pub original_length: usize,
545 pub summary_length: usize,
547 pub compression_ratio: f32,
549 pub language: String,
551 pub status: String,
553 pub message: String,
555 pub metadata: HashMap<String, String>,
557}
558
559#[derive(Debug, Clone, Serialize, Deserialize)]
561pub struct SummarizeContextRequest {
562 pub context: String,
564 pub method: Option<SummarizationMethod>,
566 pub max_length: Option<usize>,
568 pub compression_ratio: Option<f32>,
570 pub language: Option<String>,
572}
573
574#[derive(Debug, Clone, Serialize, Deserialize)]
576pub struct SummarizeContextResponse {
577 pub summary_id: String,
579 pub original_context: String,
581 pub summary: String,
583 pub method: String,
585 pub original_length: usize,
587 pub summary_length: usize,
589 pub compression_ratio: f32,
591 pub language: String,
593 pub status: String,
595 pub message: String,
597 pub metadata: HashMap<String, String>,
599}
600
601#[derive(Debug, Clone, Serialize, Deserialize)]
603pub struct GetSummaryResponse {
604 pub summary_id: String,
606 pub original_text: String,
608 pub summary: String,
610 pub method: String,
612 pub original_length: usize,
614 pub summary_length: usize,
616 pub compression_ratio: f32,
618 pub language: String,
620 pub created_at: String,
622 pub metadata: HashMap<String, String>,
624 pub status: String,
626}
627
628#[derive(Debug, Clone, Serialize, Deserialize)]
630pub struct SummaryInfo {
631 pub summary_id: String,
633 pub method: String,
635 pub language: String,
637 pub original_length: usize,
639 pub summary_length: usize,
641 pub compression_ratio: f32,
643 pub created_at: String,
645 pub metadata: HashMap<String, String>,
647}
648
649#[derive(Debug, Clone, Serialize, Deserialize)]
651pub struct ListSummariesResponse {
652 pub summaries: Vec<SummaryInfo>,
654 pub total_count: usize,
656 pub status: String,
658}
659
660#[derive(Debug, Clone, Serialize, Deserialize)]
662pub struct IndexingProgress {
663 pub is_indexing: bool,
665 pub overall_status: String,
667 pub collections: Vec<CollectionProgress>,
669}
670
671#[derive(Debug, Clone, Serialize, Deserialize)]
673pub struct CollectionProgress {
674 pub collection_name: String,
676 pub status: String,
678 pub progress: f32,
680 pub vector_count: usize,
682 pub error_message: Option<String>,
684 pub last_updated: String,
686}
687
688#[derive(Debug, Clone, Serialize, Deserialize)]
692pub struct IntelligentSearchRequest {
693 pub query: String,
695 pub collections: Option<Vec<String>>,
697 pub max_results: Option<usize>,
699 pub domain_expansion: Option<bool>,
701 pub technical_focus: Option<bool>,
703 pub mmr_enabled: Option<bool>,
705 pub mmr_lambda: Option<f32>,
707}
708
709#[derive(Debug, Clone, Serialize, Deserialize)]
711pub struct SemanticSearchRequest {
712 pub query: String,
714 pub collection: String,
716 pub max_results: Option<usize>,
718 pub semantic_reranking: Option<bool>,
720 pub cross_encoder_reranking: Option<bool>,
722 pub similarity_threshold: Option<f32>,
724}
725
726#[derive(Debug, Clone, Serialize, Deserialize)]
728pub struct ContextualSearchRequest {
729 pub query: String,
731 pub collection: String,
733 pub context_filters: Option<HashMap<String, serde_json::Value>>,
735 pub max_results: Option<usize>,
737 pub context_reranking: Option<bool>,
739 pub context_weight: Option<f32>,
741}
742
743#[derive(Debug, Clone, Serialize, Deserialize)]
745pub struct MultiCollectionSearchRequest {
746 pub query: String,
748 pub collections: Vec<String>,
750 pub max_per_collection: Option<usize>,
752 pub max_total_results: Option<usize>,
754 pub cross_collection_reranking: Option<bool>,
756}
757
758#[derive(Debug, Clone, Serialize, Deserialize)]
760pub struct IntelligentSearchResult {
761 pub id: String,
763 pub score: f32,
765 pub content: String,
767 pub metadata: Option<HashMap<String, serde_json::Value>>,
769 pub collection: Option<String>,
771 pub query_used: Option<String>,
773}
774
775#[derive(Debug, Clone, Serialize, Deserialize)]
777pub struct IntelligentSearchResponse {
778 pub results: Vec<IntelligentSearchResult>,
780 pub total_results: usize,
782 pub duration_ms: u64,
784 pub queries_generated: Option<Vec<String>>,
786 pub collections_searched: Option<Vec<String>>,
788 pub metadata: Option<HashMap<String, serde_json::Value>>,
790}
791
792#[derive(Debug, Clone, Serialize, Deserialize)]
794pub struct SemanticSearchResponse {
795 pub results: Vec<IntelligentSearchResult>,
797 pub total_results: usize,
799 pub duration_ms: u64,
801 pub collection: String,
803 pub metadata: Option<HashMap<String, serde_json::Value>>,
805}
806
807#[derive(Debug, Clone, Serialize, Deserialize)]
809pub struct ContextualSearchResponse {
810 pub results: Vec<IntelligentSearchResult>,
812 pub total_results: usize,
814 pub duration_ms: u64,
816 pub collection: String,
818 pub context_filters: Option<HashMap<String, serde_json::Value>>,
820 pub metadata: Option<HashMap<String, serde_json::Value>>,
822}
823
824#[derive(Debug, Clone, Serialize, Deserialize)]
826pub struct MultiCollectionSearchResponse {
827 pub results: Vec<IntelligentSearchResult>,
829 pub total_results: usize,
831 pub duration_ms: u64,
833 pub collections_searched: Vec<String>,
835 pub results_per_collection: Option<HashMap<String, usize>>,
837 pub metadata: Option<HashMap<String, serde_json::Value>>,
839}
840
841#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
845#[serde(rename_all = "PascalCase")]
846pub enum ReplicaStatus {
847 Connected,
849 Syncing,
851 Lagging,
853 Disconnected,
855}
856
857#[derive(Debug, Clone, Serialize, Deserialize)]
859pub struct ReplicaInfo {
860 pub replica_id: String,
862 pub host: String,
864 pub port: u16,
866 pub status: String,
868 pub last_heartbeat: DateTime<Utc>,
870 pub operations_synced: u64,
872
873 #[serde(skip_serializing_if = "Option::is_none")]
876 pub offset: Option<u64>,
877 #[serde(skip_serializing_if = "Option::is_none")]
879 pub lag: Option<u64>,
880}
881
882#[derive(Debug, Clone, Serialize, Deserialize)]
884pub struct ReplicationStats {
885 #[serde(skip_serializing_if = "Option::is_none")]
888 pub role: Option<String>,
889 #[serde(skip_serializing_if = "Option::is_none")]
891 pub bytes_sent: Option<u64>,
892 #[serde(skip_serializing_if = "Option::is_none")]
894 pub bytes_received: Option<u64>,
895 #[serde(skip_serializing_if = "Option::is_none")]
897 pub last_sync: Option<DateTime<Utc>>,
898 #[serde(skip_serializing_if = "Option::is_none")]
900 pub operations_pending: Option<usize>,
901 #[serde(skip_serializing_if = "Option::is_none")]
903 pub snapshot_size: Option<usize>,
904 #[serde(skip_serializing_if = "Option::is_none")]
906 pub connected_replicas: Option<usize>,
907
908 pub master_offset: u64,
911 pub replica_offset: u64,
913 pub lag_operations: u64,
915 pub total_replicated: u64,
917}
918
919#[derive(Debug, Clone, Serialize, Deserialize)]
921pub struct ReplicationStatusResponse {
922 pub status: String,
924 pub stats: ReplicationStats,
926 #[serde(skip_serializing_if = "Option::is_none")]
928 pub message: Option<String>,
929}
930
931#[derive(Debug, Clone, Serialize, Deserialize)]
933pub struct ReplicaListResponse {
934 pub replicas: Vec<ReplicaInfo>,
936 pub count: usize,
938 pub message: String,
940}