vectorizer-sdk 3.2.0

Rust SDK for Vectorizer — RPC-first (vectorizer://) with HTTP fallback
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
//! Data models for the Vectorizer SDK

use std::collections::HashMap;

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

// Re-export hybrid search models
pub mod hybrid_search;
pub use hybrid_search::*;

// Re-export graph models
pub mod graph;
pub use graph::*;

// Re-export file upload models
pub mod file_upload;
pub use file_upload::*;

// ===== CLIENT-SIDE REPLICATION CONFIGURATION =====

/// Read preference for routing read operations.
/// Similar to MongoDB's read preferences.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ReadPreference {
    /// Route all reads to master
    Master,
    /// Route reads to replicas (round-robin)
    #[default]
    Replica,
    /// Route to the node with lowest latency
    Nearest,
}

/// Host configuration for master/replica topology.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HostConfig {
    /// Master node URL (receives all write operations)
    pub master: String,
    /// Replica node URLs (receive read operations based on read_preference)
    pub replicas: Vec<String>,
}

/// Options that can be passed to read operations for per-operation override.
#[derive(Debug, Clone, Default)]
pub struct ReadOptions {
    /// Override the default read preference for this operation
    pub read_preference: Option<ReadPreference>,
}

/// Vector similarity metrics
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum SimilarityMetric {
    /// Cosine similarity
    #[default]
    Cosine,
    /// Euclidean distance
    Euclidean,
    /// Dot product
    DotProduct,
}

/// Vector representation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Vector {
    /// Unique identifier for the vector
    pub id: String,
    /// Vector data as an array of numbers
    pub data: Vec<f32>,
    /// Optional metadata associated with the vector
    pub metadata: Option<HashMap<String, serde_json::Value>>,
    /// Optional ECC public key for payload encryption (PEM, base64, or hex format)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub public_key: Option<String>,
}

/// Collection representation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Collection {
    /// Collection name
    pub name: String,
    /// Vector dimension
    pub dimension: usize,
    /// Similarity metric used for search (API may return as 'metric')
    #[serde(alias = "similarity_metric")]
    pub metric: Option<String>,
    /// Optional description
    #[serde(default)]
    pub description: Option<String>,
    /// Creation timestamp
    #[serde(default)]
    pub created_at: Option<String>,
    /// Last update timestamp
    #[serde(default)]
    pub updated_at: Option<String>,
    /// Vector count
    #[serde(default)]
    pub vector_count: usize,
    /// Document count
    #[serde(default)]
    pub document_count: usize,
    /// Embedding provider
    #[serde(default)]
    pub embedding_provider: Option<String>,
    /// Indexing status
    #[serde(default)]
    pub indexing_status: Option<serde_json::Value>,
    /// Normalization config
    #[serde(default)]
    pub normalization: Option<serde_json::Value>,
    /// Quantization config
    #[serde(default)]
    pub quantization: Option<serde_json::Value>,
    /// Size info
    #[serde(default)]
    pub size: Option<serde_json::Value>,
}

/// Collection information.
///
/// The v3.0.0 REST surface returns `metric` in Rust-Debug form
/// (e.g. `"Cosine"`), plus new top-level blocks (`size`, `quantization`,
/// `normalization`, `status`). Every field beyond `name` + `dimension`
/// carries `#[serde(default)]` so the model tolerates pre-v3 servers
/// and future additions (request models keep the strict posture; this
/// is a response-only struct).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollectionInfo {
    /// Collection name
    pub name: String,
    /// Vector dimension
    pub dimension: usize,
    /// Similarity metric used for search. The v3 server emits this in
    /// Rust-Debug form (`"Cosine"` / `"Euclidean"` / `"DotProduct"`);
    /// callers that compare against `"cosine"` etc. should go through
    /// `.to_lowercase()`.
    #[serde(default, alias = "similarity_metric")]
    pub metric: String,
    /// Number of vectors in the collection
    #[serde(default)]
    pub vector_count: usize,
    /// Number of documents in the collection
    #[serde(default)]
    pub document_count: usize,
    /// Creation timestamp (RFC3339). Optional — pre-v3 servers may omit.
    #[serde(default)]
    pub created_at: String,
    /// Last update timestamp (RFC3339). Optional — pre-v3 servers may omit.
    #[serde(default)]
    pub updated_at: String,
    /// Indexing status. Absent on the v3 server; some legacy servers send it.
    #[serde(default)]
    pub indexing_status: Option<IndexingStatus>,
    /// Size block emitted by v3 (`{total, total_bytes, index, index_bytes,
    /// payload, payload_bytes}`).
    #[serde(default)]
    pub size: Option<serde_json::Value>,
    /// Quantization block emitted by v3 (`{enabled, type, bits}`).
    #[serde(default)]
    pub quantization: Option<serde_json::Value>,
    /// Normalization block emitted by v3.
    #[serde(default)]
    pub normalization: Option<serde_json::Value>,
    /// Ready/indexing/error state emitted by v3.
    #[serde(default)]
    pub status: Option<String>,
}

/// Indexing status.
///
/// Every field carries `#[serde(default)]` to match the tolerant
/// posture of the parent [`CollectionInfo`] — the v3 server emits a
/// subset of this shape (`status`/`progress`/`total_documents`/
/// `processed_documents` plus some extra keys this struct doesn't
/// model) and omits `vector_count` and `last_updated`, which used to
/// make `serde_json::from_str::<CollectionInfo>` fail on a
/// `Collection → JSON → CollectionInfo` round-trip through
/// `Collection::indexing_status: Option<serde_json::Value>` that
/// preserves the server's partial shape.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IndexingStatus {
    /// Status
    #[serde(default)]
    pub status: String,
    /// Progress percentage
    #[serde(default)]
    pub progress: f32,
    /// Total documents
    #[serde(default)]
    pub total_documents: usize,
    /// Processed documents
    #[serde(default)]
    pub processed_documents: usize,
    /// Vector count
    #[serde(default)]
    pub vector_count: usize,
    /// Estimated time remaining
    #[serde(default)]
    pub estimated_time_remaining: Option<String>,
    /// Last updated timestamp
    #[serde(default)]
    pub last_updated: String,
}

/// Search result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResult {
    /// Vector ID
    pub id: String,
    /// Similarity score
    pub score: f32,
    /// Vector content (if available)
    pub content: Option<String>,
    /// Optional metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Search response.
///
/// `query_time_ms` defaults to `0.0` because the v3.0.x server's text
/// search handler doesn't emit it — callers that need elapsed timing
/// should measure client-side. Same tolerance applies to the
/// additional diagnostic fields the server may add in later versions.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResponse {
    /// Search results.
    #[serde(default)]
    pub results: Vec<SearchResult>,
    /// Query time in milliseconds (server-reported; 0.0 when the
    /// server omits it).
    #[serde(default)]
    pub query_time_ms: f64,
    /// Echo of the original query string, if the server returned one.
    #[serde(default)]
    pub query: Option<String>,
    /// Echo of the requested result limit, if the server returned one.
    #[serde(default)]
    pub limit: Option<usize>,
    /// Echo of the collection name, if the server returned one.
    #[serde(default)]
    pub collection: Option<String>,
}

/// Embedding request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmbeddingRequest {
    /// Text to embed
    pub text: String,
    /// Optional model to use for embedding
    pub model: Option<String>,
    /// Optional parameters for embedding generation
    pub parameters: Option<EmbeddingParameters>,
}

/// Embedding parameters
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmbeddingParameters {
    /// Maximum sequence length
    pub max_length: Option<usize>,
    /// Whether to normalize the embedding
    pub normalize: Option<bool>,
    /// Optional prefix for the text
    pub prefix: Option<String>,
}

/// Embedding response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmbeddingResponse {
    /// Generated embedding vector
    pub embedding: Vec<f32>,
    /// Model used for embedding
    pub model: String,
    /// Text that was embedded
    pub text: String,
    /// Embedding dimension
    pub dimension: usize,
    /// Provider used
    pub provider: String,
}

/// Health status
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthStatus {
    /// Service status
    pub status: String,
    /// Service version
    pub version: String,
    /// Timestamp
    pub timestamp: String,
    /// Uptime in seconds
    pub uptime: Option<u64>,
    /// Number of collections
    pub collections: Option<usize>,
    /// Total number of vectors
    pub total_vectors: Option<usize>,
}

/// Collections list response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollectionsResponse {
    /// List of collections
    pub collections: Vec<Collection>,
}

/// Create collection response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateCollectionResponse {
    /// Success message
    pub message: String,
    /// Collection name
    pub collection: String,
}

/// Database statistics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseStats {
    /// Total number of collections
    pub total_collections: usize,
    /// Total number of vectors
    pub total_vectors: usize,
    /// Total memory estimate in bytes
    pub total_memory_estimate_bytes: usize,
    /// Collections information
    pub collections: Vec<CollectionStats>,
}

/// Collection statistics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollectionStats {
    /// Collection name
    pub name: String,
    /// Number of vectors
    pub vector_count: usize,
    /// Vector dimension
    pub dimension: usize,
    /// Memory estimate in bytes
    pub memory_estimate_bytes: usize,
}

/// Batch text request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchTextRequest {
    /// Text ID
    pub id: String,
    /// Text content
    pub text: String,
    /// Optional metadata
    pub metadata: Option<HashMap<String, String>>,
}

/// Batch configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchConfig {
    /// Maximum batch size
    pub max_batch_size: Option<usize>,
    /// Number of parallel workers
    pub parallel_workers: Option<usize>,
    /// Whether operations should be atomic
    pub atomic: Option<bool>,
}

/// Batch insert request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchInsertRequest {
    /// Texts to insert
    pub texts: Vec<BatchTextRequest>,
    /// Batch configuration
    pub config: Option<BatchConfig>,
}

/// Batch response.
///
/// Tolerant of both the old (pre-v3) `{success, operation, total_operations,
/// successful_operations, failed_operations, duration_ms, errors}` shape
/// and the v3.0.x server's `/insert_texts` response
/// `{collection, count, inserted, failed, results}`. All fields default to
/// empty/zero/false when absent so callers can match on whichever pair the
/// running server emits without branching on version.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchResponse {
    /// Whether the operation was successful (pre-v3 shape; v3 emits
    /// `inserted`/`failed` instead — left `false` and the caller
    /// should inspect `successful_operations > 0 && failed_operations == 0`).
    #[serde(default)]
    pub success: bool,
    /// Collection name (both shapes emit this).
    #[serde(default)]
    pub collection: String,
    /// Operation type (pre-v3 only; v3 omits).
    #[serde(default)]
    pub operation: String,
    /// Total number of operations (pre-v3 shape). v3 emits `count` —
    /// normalised into this field via the alias.
    #[serde(default, alias = "count")]
    pub total_operations: usize,
    /// Number of successful operations (pre-v3 shape). v3 emits
    /// `inserted` — aliased so either maps onto this field.
    #[serde(default, alias = "inserted")]
    pub successful_operations: usize,
    /// Number of failed operations. Same field name in both shapes.
    #[serde(default, alias = "failed")]
    pub failed_operations: usize,
    /// Duration in milliseconds (pre-v3 only).
    #[serde(default)]
    pub duration_ms: u64,
    /// Error messages (pre-v3 shape).
    #[serde(default)]
    pub errors: Vec<String>,
    /// Per-entry result records emitted by v3 `/insert_texts`. Each
    /// record carries the client-sent id (`client_id`) and the
    /// server-assigned UUIDs under `vector_ids`; use this when the
    /// server reassigns ids on insert.
    #[serde(default)]
    pub results: Vec<BatchResultEntry>,
}

/// One entry in `BatchResponse::results` as emitted by the v3
/// `/insert_texts` handler. Carries the client-provided id alongside
/// the server-assigned vector UUID(s) so callers can round-trip the
/// mapping when they need idempotency by client id.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchResultEntry {
    /// Original `id` the caller sent in `BatchTextRequest`.
    #[serde(default)]
    pub client_id: String,
    /// Zero-based index of the entry in the original batch.
    #[serde(default)]
    pub index: usize,
    /// `"ok"` or `"error"`.
    #[serde(default)]
    pub status: String,
    /// Whether the server chunked the input (long text → multiple
    /// vectors).
    #[serde(default)]
    pub chunked: bool,
    /// Server-assigned UUID(s) — one element unless `chunked` is true.
    #[serde(default)]
    pub vector_ids: Vec<String>,
    /// Count of vectors created for this entry (≥1 if `chunked`).
    #[serde(default)]
    pub vectors_created: usize,
    /// Populated only on `status == "error"`.
    #[serde(default)]
    pub error: Option<String>,
}

/// Batch search query
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchSearchQuery {
    /// Query text
    pub query: String,
    /// Maximum number of results
    pub limit: Option<usize>,
    /// Minimum score threshold
    pub score_threshold: Option<f32>,
}

/// Batch search request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchSearchRequest {
    /// Search queries
    pub queries: Vec<BatchSearchQuery>,
    /// Batch configuration
    pub config: Option<BatchConfig>,
}

/// Batch search response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchSearchResponse {
    /// Whether the operation was successful
    pub success: bool,
    /// Collection name
    pub collection: String,
    /// Total number of queries
    pub total_queries: usize,
    /// Number of successful queries
    pub successful_queries: usize,
    /// Number of failed queries
    pub failed_queries: usize,
    /// Duration in milliseconds
    pub duration_ms: u64,
    /// Search results
    pub results: Vec<Vec<SearchResult>>,
    /// Error messages
    pub errors: Vec<String>,
}

/// Batch vector update
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchVectorUpdate {
    /// Vector ID
    pub id: String,
    /// New vector data (optional)
    pub data: Option<Vec<f32>>,
    /// New metadata (optional)
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Batch update request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchUpdateRequest {
    /// Vector updates
    pub updates: Vec<BatchVectorUpdate>,
    /// Batch configuration
    pub config: Option<BatchConfig>,
}

/// Batch delete request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchDeleteRequest {
    /// Vector IDs to delete
    pub vector_ids: Vec<String>,
    /// Batch configuration
    pub config: Option<BatchConfig>,
}

/// Summarization methods
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum SummarizationMethod {
    /// Extractive summarization
    #[default]
    Extractive,
    /// Keyword summarization
    Keyword,
    /// Sentence summarization
    Sentence,
    /// Abstractive summarization
    Abstractive,
}

/// Summarize text request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SummarizeTextRequest {
    /// Text to summarize
    pub text: String,
    /// Summarization method
    pub method: Option<SummarizationMethod>,
    /// Maximum summary length
    pub max_length: Option<usize>,
    /// Compression ratio
    pub compression_ratio: Option<f32>,
    /// Language code
    pub language: Option<String>,
}

/// Summarize text response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SummarizeTextResponse {
    /// Summary ID
    pub summary_id: String,
    /// Original text
    pub original_text: String,
    /// Generated summary
    pub summary: String,
    /// Method used
    pub method: String,
    /// Original text length
    pub original_length: usize,
    /// Summary length
    pub summary_length: usize,
    /// Compression ratio
    pub compression_ratio: f32,
    /// Language
    pub language: String,
    /// Status
    pub status: String,
    /// Message
    pub message: String,
    /// Metadata
    pub metadata: HashMap<String, String>,
}

/// Summarize context request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SummarizeContextRequest {
    /// Context to summarize
    pub context: String,
    /// Summarization method
    pub method: Option<SummarizationMethod>,
    /// Maximum summary length
    pub max_length: Option<usize>,
    /// Compression ratio
    pub compression_ratio: Option<f32>,
    /// Language code
    pub language: Option<String>,
}

/// Summarize context response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SummarizeContextResponse {
    /// Summary ID
    pub summary_id: String,
    /// Original context
    pub original_context: String,
    /// Generated summary
    pub summary: String,
    /// Method used
    pub method: String,
    /// Original context length
    pub original_length: usize,
    /// Summary length
    pub summary_length: usize,
    /// Compression ratio
    pub compression_ratio: f32,
    /// Language
    pub language: String,
    /// Status
    pub status: String,
    /// Message
    pub message: String,
    /// Metadata
    pub metadata: HashMap<String, String>,
}

/// Get summary response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetSummaryResponse {
    /// Summary ID
    pub summary_id: String,
    /// Original text
    pub original_text: String,
    /// Generated summary
    pub summary: String,
    /// Method used
    pub method: String,
    /// Original text length
    pub original_length: usize,
    /// Summary length
    pub summary_length: usize,
    /// Compression ratio
    pub compression_ratio: f32,
    /// Language
    pub language: String,
    /// Creation timestamp
    pub created_at: String,
    /// Metadata
    pub metadata: HashMap<String, String>,
    /// Status
    pub status: String,
}

/// Summary info
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SummaryInfo {
    /// Summary ID
    pub summary_id: String,
    /// Method used
    pub method: String,
    /// Language
    pub language: String,
    /// Original text length
    pub original_length: usize,
    /// Summary length
    pub summary_length: usize,
    /// Compression ratio
    pub compression_ratio: f32,
    /// Creation timestamp
    pub created_at: String,
    /// Metadata
    pub metadata: HashMap<String, String>,
}

/// List summaries response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListSummariesResponse {
    /// List of summaries
    pub summaries: Vec<SummaryInfo>,
    /// Total count
    pub total_count: usize,
    /// Status
    pub status: String,
}

/// Indexing progress
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IndexingProgress {
    /// Whether indexing is in progress
    pub is_indexing: bool,
    /// Overall status
    pub overall_status: String,
    /// Collections being indexed
    pub collections: Vec<CollectionProgress>,
}

/// Collection progress
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollectionProgress {
    /// Collection name
    pub collection_name: String,
    /// Status
    pub status: String,
    /// Progress percentage
    pub progress: f32,
    /// Vector count
    pub vector_count: usize,
    /// Error message if any
    pub error_message: Option<String>,
    /// Last updated timestamp
    pub last_updated: String,
}

// ===== INTELLIGENT SEARCH MODELS =====

/// Intelligent search request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IntelligentSearchRequest {
    /// Search query
    pub query: String,
    /// Collections to search (optional - searches all if not specified)
    pub collections: Option<Vec<String>>,
    /// Maximum number of results
    pub max_results: Option<usize>,
    /// Enable domain expansion
    pub domain_expansion: Option<bool>,
    /// Enable technical focus
    pub technical_focus: Option<bool>,
    /// Enable MMR diversification
    pub mmr_enabled: Option<bool>,
    /// MMR balance parameter (0.0-1.0)
    pub mmr_lambda: Option<f32>,
}

/// Semantic search request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SemanticSearchRequest {
    /// Search query
    pub query: String,
    /// Collection to search
    pub collection: String,
    /// Maximum number of results
    pub max_results: Option<usize>,
    /// Enable semantic reranking
    pub semantic_reranking: Option<bool>,
    /// Enable cross-encoder reranking
    pub cross_encoder_reranking: Option<bool>,
    /// Minimum similarity threshold
    pub similarity_threshold: Option<f32>,
}

/// Contextual search request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextualSearchRequest {
    /// Search query
    pub query: String,
    /// Collection to search
    pub collection: String,
    /// Metadata-based context filters
    pub context_filters: Option<HashMap<String, serde_json::Value>>,
    /// Maximum number of results
    pub max_results: Option<usize>,
    /// Enable context-aware reranking
    pub context_reranking: Option<bool>,
    /// Weight of context factors (0.0-1.0)
    pub context_weight: Option<f32>,
}

/// Multi-collection search request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiCollectionSearchRequest {
    /// Search query
    pub query: String,
    /// Collections to search
    pub collections: Vec<String>,
    /// Maximum results per collection
    pub max_per_collection: Option<usize>,
    /// Maximum total results
    pub max_total_results: Option<usize>,
    /// Enable cross-collection reranking
    pub cross_collection_reranking: Option<bool>,
}

/// Intelligent search result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IntelligentSearchResult {
    /// Result ID
    pub id: String,
    /// Similarity score
    pub score: f32,
    /// Result content
    pub content: String,
    /// Metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
    /// Collection name
    pub collection: Option<String>,
    /// Query used for this result
    pub query_used: Option<String>,
}

/// Intelligent search response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IntelligentSearchResponse {
    /// Search results
    pub results: Vec<IntelligentSearchResult>,
    /// Total number of results found
    pub total_results: usize,
    /// Search duration in milliseconds
    pub duration_ms: u64,
    /// Queries generated
    pub queries_generated: Option<Vec<String>>,
    /// Collections searched
    pub collections_searched: Option<Vec<String>>,
    /// Search metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Semantic search response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SemanticSearchResponse {
    /// Search results
    pub results: Vec<IntelligentSearchResult>,
    /// Total number of results found
    pub total_results: usize,
    /// Search duration in milliseconds
    pub duration_ms: u64,
    /// Collection searched
    pub collection: String,
    /// Search metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Contextual search response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextualSearchResponse {
    /// Search results
    pub results: Vec<IntelligentSearchResult>,
    /// Total number of results found
    pub total_results: usize,
    /// Search duration in milliseconds
    pub duration_ms: u64,
    /// Collection searched
    pub collection: String,
    /// Context filters applied
    pub context_filters: Option<HashMap<String, serde_json::Value>>,
    /// Search metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Multi-collection search response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiCollectionSearchResponse {
    /// Search results
    pub results: Vec<IntelligentSearchResult>,
    /// Total number of results found
    pub total_results: usize,
    /// Search duration in milliseconds
    pub duration_ms: u64,
    /// Collections searched
    pub collections_searched: Vec<String>,
    /// Results per collection
    pub results_per_collection: Option<HashMap<String, usize>>,
    /// Search metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

// ==================== REPLICATION MODELS ====================

/// Status of a replica node
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub enum ReplicaStatus {
    /// Replica is connected and healthy
    Connected,
    /// Replica is syncing data
    Syncing,
    /// Replica is lagging behind master
    Lagging,
    /// Replica is disconnected
    Disconnected,
}

/// Information about a replica node
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplicaInfo {
    /// Unique identifier for the replica
    pub replica_id: String,
    /// Hostname or IP address of the replica
    pub host: String,
    /// Port number of the replica
    pub port: u16,
    /// Current status of the replica
    pub status: String,
    /// Timestamp of last heartbeat
    pub last_heartbeat: DateTime<Utc>,
    /// Number of operations successfully synced
    pub operations_synced: u64,

    // Legacy fields (backwards compatible)
    /// Legacy: Current offset on replica (deprecated, use operations_synced)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u64>,
    /// Legacy: Lag in operations (deprecated, use status)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lag: Option<u64>,
}

/// Statistics for replication status
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplicationStats {
    // New fields (v1.2.0+)
    /// Role of the node: Master or Replica
    #[serde(skip_serializing_if = "Option::is_none")]
    pub role: Option<String>,
    /// Total bytes sent to replicas (Master only)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bytes_sent: Option<u64>,
    /// Total bytes received from master (Replica only)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bytes_received: Option<u64>,
    /// Timestamp of last synchronization
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_sync: Option<DateTime<Utc>>,
    /// Number of operations pending replication
    #[serde(skip_serializing_if = "Option::is_none")]
    pub operations_pending: Option<usize>,
    /// Size of snapshot data in bytes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_size: Option<usize>,
    /// Number of connected replicas (Master only)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub connected_replicas: Option<usize>,

    // Legacy fields (backwards compatible - always present)
    /// Current offset on master node
    pub master_offset: u64,
    /// Current offset on replica node
    pub replica_offset: u64,
    /// Number of operations behind
    pub lag_operations: u64,
    /// Total operations replicated
    pub total_replicated: u64,
}

/// Response for replication status endpoint
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplicationStatusResponse {
    /// Overall status message
    pub status: String,
    /// Detailed replication statistics
    pub stats: ReplicationStats,
    /// Optional message with additional information
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

/// Response for listing replicas
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplicaListResponse {
    /// List of replica nodes
    pub replicas: Vec<ReplicaInfo>,
    /// Total count of replicas
    pub count: usize,
    /// Status message
    pub message: String,
}