vectorizer-sdk 3.3.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
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
# Vectorizer Rust SDK


[![Crates.io](https://img.shields.io/crates/v/vectorizer-sdk.svg)](https://crates.io/crates/vectorizer-sdk)
[![Documentation](https://docs.rs/vectorizer-sdk/badge.svg)](https://docs.rs/vectorizer-sdk)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)

High-performance Rust SDK for Vectorizer vector database.

**Package**: `vectorizer-sdk`  
**Version**: 3.2.0 (RPC-first; HTTP fallback retained)

## v3.2 — backpressure-aware HTTP client (HTTP 429 + `Retry-After`)


The HTTP transport honors the server-side bulk-upsert backpressure
shipped in Vectorizer 3.2.0
([#263](https://github.com/hivellm/vectorizer/issues/263)). On HTTP
`429 Too Many Requests` the client parses `Retry-After` (seconds
form, 1 s default, 30 s cap), sleeps, and retries up to 3 times
before surfacing `VectorizerError::RateLimit`. Pre-3.2.0 clients
bounced 429s into a generic 5xx and lost the retry budget. The
`vectorizer-sdk` parses `Retry-After` via `parse_retry_after_secs`
in `src/http_transport.rs`; lock-in tests live at
`tests/retry_after_parse.rs`.

## v3.1 — `/insert_vectors` + stable client-id upserts


- `VectorizerClient::insert_vectors(...)` — bulk-insert pre-computed
  embeddings with caller-supplied vector ids. Skips the embedding
  pipeline entirely.
- `insert` / `insert_texts`: the request `id` is now used verbatim
  as the stored `Vector.id` (non-chunked) or as `<id>#<chunk_index>`
  (chunked). Re-running the same payload upserts in place.
- Chunked vectors expose a flat payload layout (`{content,
  file_path, chunk_index, parent_id, ...user_metadata}`); legacy
  nested payloads from ≤ 3.0.x stay readable during the deprecation
  window.

Client-id contract: non-empty, length ≤ 256, no leading/trailing
whitespace, must not contain `#`.

## ✅ Status: v3.0.0 — VectorizerRPC default transport


**v3.x ships with VectorizerRPC** — length-prefixed MessagePack over
raw TCP — as the recommended primary transport. The HTTP path that
shipped in 2.x stays available behind the `http` Cargo feature
(default-on for backward compat). Pick the constructor that matches
the URL scheme you have:

| URL | Constructor | Transport |
|---|---|---|
| `vectorizer://host:15503` | `RpcClient::connect_url(url)` | Binary RPC (recommended) |
| `vectorizer://host` | `RpcClient::connect_url(url)` | RPC on default port 15503 |
| `host:15503` (no scheme) | `RpcClient::connect_url(url)` or `RpcClient::connect("host:port")` | RPC |
| `http://host:15002` | `VectorizerClient` (HTTP path below) | REST (legacy) |

## Quick Start (RPC, recommended)


```toml
[dependencies]
vectorizer-sdk = "3.2"
tokio = { version = "1", features = ["full"] }
```

```rust
use vectorizer_sdk::rpc::{HelloPayload, RpcClient};

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect via the canonical vectorizer:// URL.
    let client = RpcClient::connect_url("vectorizer://127.0.0.1:15503").await?;

    // HELLO is mandatory before any data-plane command. In single-user
    // mode (server's `auth.enabled: false`) credentials are ignored;
    // when auth is enabled, attach a JWT or API key:
    //   HelloPayload::new("my-app").with_token("<jwt>")
    let hello = client.hello(HelloPayload::new("my-app/1.0")).await?;
    println!("server={}, capabilities: {:?}", hello.server_version, hello.capabilities);

    // Typed wrappers cover every v1 command.
    let collections = client.list_collections().await?;
    if let Some(name) = collections.first() {
        let info = client.get_collection_info(name).await?;
        println!("{name}: {} vectors, dim={}", info.vector_count, info.dimension);

        let hits = client.search_basic(name, "vector database", 5).await?;
        for hit in &hits {
            println!("  {} (score={:.3})", hit.id, hit.score);
        }
    }
    Ok(())
}
```

See `examples/rpc_quickstart.rs` for the runnable version. Wire spec:
[`docs/specs/VECTORIZER_RPC.md`](../../docs/specs/VECTORIZER_RPC.md).

### Connection pooling


```rust
use vectorizer_sdk::rpc::{HelloPayload, RpcPool, pool::RpcPoolConfig};

let pool = RpcPool::new(RpcPoolConfig {
    address: "127.0.0.1:15503".into(),
    max_connections: 8,
    hello: HelloPayload::new("worker"),
});

let conn = pool.acquire().await?;
let collections = conn.client().list_collections().await?;
// `conn` returns to the pool on Drop.
```

### Error handling


`RpcClient` returns `Result<T, RpcClientError>`. The variants:

- `Io(std::io::Error)` — TCP-level failure.
- `Server(String)` — server returned `Err(message)`.
- `ConnectionClosed` — the background reader task exited (peer
  closed, or write failure mid-call).
- `NotAuthenticated` — local guard against issuing a data-plane
  command before `HELLO` succeeded; saves an unnecessary round-trip.
- `Encode(rmp_serde::encode::Error)` — should be unreachable for v1
  shapes (every type derives `Serialize`).

## Quick Start (HTTP, legacy)


The 2.x `VectorizerClient` is preserved unchanged. The flat
1,989-line `client.rs` was split into a per-surface module tree in
the `phase4_split-sdk-rust-client` refactor — every public method
keeps its name and signature, but the implementation now lives
next to the surface it belongs to:

```
sdks/rust/src/
├── transport.rs        # Transport trait (impl by HttpTransport, RpcTransport, ...)
├── http_transport.rs   # REST backend
├── rpc/                # RPC backend (default in v3.x)
└── client/             # REST facade, split per API surface
    ├── mod.rs          # struct VectorizerClient + ctors + with_transport()
    ├── core.rs         # health_check
    ├── collections.rs  # list/create/get/delete collection
    ├── vectors.rs      # get_vector, insert_texts, embed_text
    ├── search.rs       # search_vectors, intelligent/semantic/contextual/hybrid/multi
    ├── discovery.rs    # discover, filter/score/expand
    ├── files.rs        # 10 file-ops + upload + upload_config
    ├── graph.rs        # 10 graph ops (nodes, edges, path, discovery)
    └── qdrant.rs       # 25 Qdrant-compatible /qdrant/* endpoints
```

Rust permits multiple `impl` blocks for the same struct across
files of the same module, so every per-surface file just adds an
`impl VectorizerClient { ... }` block. The struct definition,
constructors, transport selection (`get_read_transport` /
`get_write_transport`), and the `make_request` helper live in
`client/mod.rs`; per-surface files only contain the user-facing
methods.

### RPC-readiness regression guard


`VectorizerClient::with_transport(Arc<dyn Transport>, base_url)` is
exposed as the test-only entry point that builds the client from
any `Transport` implementation. The
`tests/mock_transport_regression.rs` integration test exercises one
method from each of the eight per-surface modules through an
in-memory mock, proving the surface modules don't hard-code
`HttpTransport`. When `phase6_sdk-rust-rpc`'s `RpcTransport` lands,
it satisfies the same `Transport` trait — every per-surface call
routes through it without a single per-method edit.

To opt into a slim build with RPC only:

```toml
[dependencies]
vectorizer-sdk = { version = "3.0", default-features = false, features = ["rpc"] }
```

To use the HTTP client:

```rust
use vectorizer_sdk::*;

#[tokio::main]

async fn main() -> Result<()> {
    // Create client
    let client = VectorizerClient::new_default()?;

    // Health check
    let health = client.health_check().await?;
    println!("Status: {}", health.status);

    // List collections
    let collections = client.list_collections().await?;
    println!("Found {} collections", collections.len());

    // Create new collection
    let collection = client.create_collection("my_docs", 384, Some(SimilarityMetric::Cosine)).await?;
    println!("Created collection: {}", collection.name);

    // Search existing collections
    let results = client.search_vectors("gov-bips", "bitcoin", Some(5), None).await?;
    println!("Found {} search results", results.results.len());

    // Hybrid search (dense + sparse vectors)
    use vectorizer_sdk::{HybridSearchRequest, SparseVector, HybridScoringAlgorithm};
    let sparse = SparseVector::new(
        vec![0, 5, 10, 15],
        vec![0.8, 0.6, 0.9, 0.7]
    )?;
    let hybrid_results = client.hybrid_search(HybridSearchRequest {
        collection: "my_docs".to_string(),
        query: "search query".to_string(),
        query_sparse: Some(sparse),
        alpha: 0.7,
        algorithm: HybridScoringAlgorithm::ReciprocalRankFusion,
        dense_k: 20,
        sparse_k: 20,
        final_k: 10,
    }).await?;
    println!("Found {} hybrid search results", hybrid_results.results.len());

    // Qdrant-compatible API usage
    let qdrant_collections = client.qdrant_list_collections().await?;
    println!("Qdrant collections: {:?}", qdrant_collections);

    // Intelligent search with multi-query expansion
    let intelligent_request = IntelligentSearchRequest {
        query: "machine learning algorithms".to_string(),
        collections: Some(vec!["gov-bips".to_string(), "research".to_string()]),
        max_results: Some(15),
        domain_expansion: Some(true),
        technical_focus: Some(true),
        mmr_enabled: Some(true),
        mmr_lambda: Some(0.7),
    };
    let intelligent_results = client.intelligent_search(intelligent_request).await?;
    println!("Intelligent search found {} results", intelligent_results.results.len());

    // Semantic search with reranking
    let semantic_request = SemanticSearchRequest {
        query: "neural networks".to_string(),
        collection: "gov-bips".to_string(),
        max_results: Some(10),
        semantic_reranking: Some(true),
        cross_encoder_reranking: Some(false),
        similarity_threshold: Some(0.6),
    };
    let semantic_results = client.semantic_search(semantic_request).await?;
    println!("Semantic search found {} results", semantic_results.results.len());

    // Graph Operations (requires graph enabled in collection config)
    // List all graph nodes
    let nodes = client.list_graph_nodes("documents").await?;
    println!("Graph has {} nodes", nodes.count);

    // Get neighbors of a node
    let neighbors = client.get_graph_neighbors("documents", "document1").await?;
    println!("Node has {} neighbors", neighbors.neighbors.len());

    // Find related nodes within 2 hops
    use vectorizer_sdk::models::FindRelatedRequest;
    let related = client.find_related_nodes(
        "documents",
        "document1",
        FindRelatedRequest {
            max_hops: Some(2),
            relationship_type: Some("SIMILAR_TO".to_string()),
        },
    ).await?;
    println!("Found {} related nodes", related.related.len());

    // Find shortest path between two nodes
    use vectorizer_sdk::models::FindPathRequest;
    let path = client.find_graph_path(FindPathRequest {
        collection: "documents".to_string(),
        source: "document1".to_string(),
        target: "document2".to_string(),
    }).await?;
    if path.found {
        println!("Path found: {:?}", path.path.iter().map(|n| &n.id).collect::<Vec<_>>());
    }

    // Create explicit relationship
    use vectorizer_sdk::models::CreateEdgeRequest;
    let edge = client.create_graph_edge(CreateEdgeRequest {
        collection: "documents".to_string(),
        source: "document1".to_string(),
        target: "document2".to_string(),
        relationship_type: "REFERENCES".to_string(),
        weight: Some(0.9),
    }).await?;
    println!("Created edge: {}", edge.edge_id);

    // Discover SIMILAR_TO edges for entire collection
    use vectorizer_sdk::models::DiscoverEdgesRequest;
    let discovery_result = client.discover_graph_edges(
        "documents",
        DiscoverEdgesRequest {
            similarity_threshold: Some(0.7),
            max_per_node: Some(10),
        },
    ).await?;
    println!("Discovered {} edges", discovery_result.edges_created);

    // Discover edges for a specific node
    let node_discovery = client.discover_graph_edges_for_node(
        "documents",
        "document1",
        DiscoverEdgesRequest {
            similarity_threshold: Some(0.7),
            max_per_node: Some(10),
        },
    ).await?;
    println!("Discovered {} edges for node", node_discovery.edges_created);

    // Get discovery status
    let status = client.get_graph_discovery_status("documents").await?;
    println!(
        "Discovery status: {} nodes, {} edges, {:.1}% complete",
        status.total_nodes,
        status.total_edges,
        status.progress_percentage
    );

    // Contextual search with metadata filtering
    let mut context_filters = std::collections::HashMap::new();
    context_filters.insert("category".to_string(), serde_json::Value::String("AI".to_string()));
    context_filters.insert("year".to_string(), serde_json::Value::Number(2023.into()));

    let contextual_request = ContextualSearchRequest {
        query: "deep learning".to_string(),
        collection: "gov-bips".to_string(),
        context_filters: Some(context_filters),
        max_results: Some(10),
        context_reranking: Some(true),
        context_weight: Some(0.4),
    };
    let contextual_results = client.contextual_search(contextual_request).await?;
    println!("Contextual search found {} results", contextual_results.results.len());

    // Multi-collection search
    let multi_request = MultiCollectionSearchRequest {
        query: "artificial intelligence".to_string(),
        collections: vec!["gov-bips".to_string(), "research".to_string(), "tutorials".to_string()],
        max_per_collection: Some(5),
        max_total_results: Some(20),
        cross_collection_reranking: Some(true),
    };
    let multi_results = client.multi_collection_search(multi_request).await?;
    println!("Multi-collection search found {} results", multi_results.results.len());

    Ok(())
}
```

## Features


- 🚀 **High Performance**: Optimized async transport layer
- 🔄 **Async/Await**: Full async/await support with Tokio
- 📡 **Multiple Protocols**: HTTP/HTTPS and UMICP support
- 🔍 **Semantic Search**: Vector similarity search with multiple metrics
- 🧠 **Intelligent Search**: Advanced multi-query search with domain expansion
- 🎯 **Contextual Search**: Context-aware search with metadata filtering
- 🔗 **Multi-Collection Search**: Cross-collection search with intelligent aggregation
- 📦 **Batch Operations**: Efficient bulk text insertion
- 🛡️ **Type Safety**: Strongly typed API with comprehensive error handling
- 🔧 **Easy Setup**: Simple client creation with sensible defaults
- 📊 **Health Monitoring**: Built-in health checks and statistics

## Installation


### HTTP Transport (Default)


Add to `Cargo.toml`:

```toml
[dependencies]
vectorizer-sdk = "2.2.0"
tokio = { version = "1.35", features = ["full"] }
serde_json = "1.0"
```

### UMICP Transport (High Performance)


Enable the UMICP feature for high-performance protocol support:

```toml
[dependencies]
vectorizer-sdk = { version = "2.1.0", features = ["umicp"] }
tokio = { version = "1.35", features = ["full"] }
serde_json = "1.0"
```

## Configuration


### HTTP Configuration (Default)


```rust
use vectorizer_rust_sdk::{VectorizerClient, ClientConfig};

// Default configuration
let client = VectorizerClient::new_default()?;

// Custom URL
let client = VectorizerClient::new_with_url("http://localhost:15002")?;

// With API key
let client = VectorizerClient::new_with_api_key("http://localhost:15002", "your-api-key")?;

// Advanced configuration
let client = VectorizerClient::new(ClientConfig {
    base_url: Some("http://localhost:15002".to_string()),
    api_key: Some("your-api-key".to_string()),
    timeout_secs: Some(60),
    ..Default::default()
})?;
```

### UMICP Configuration (High Performance)


[UMICP (Universal Messaging and Inter-process Communication Protocol)](https://crates.io/crates/umicp-core) provides significant performance benefits.

#### Using Connection String


```rust
use vectorizer_rust_sdk::VectorizerClient;

let client = VectorizerClient::from_connection_string(
    "umicp://localhost:15003",
    Some("your-api-key")
)?;

println!("Using protocol: {}", client.protocol());
```

#### Using Explicit Configuration


```rust
use vectorizer_rust_sdk::{VectorizerClient, ClientConfig, Protocol, UmicpConfig};

let client = VectorizerClient::new(ClientConfig {
    protocol: Some(Protocol::Umicp),
    api_key: Some("your-api-key".to_string()),
    umicp: Some(UmicpConfig {
        host: "localhost".to_string(),
        port: 15003,
    }),
    timeout_secs: Some(60),
    ..Default::default()
})?;
```

#### When to Use UMICP


Use UMICP when:

- **Large Payloads**: Inserting or searching large batches of vectors
- **High Throughput**: Need maximum performance for production workloads
- **Low Latency**: Need minimal protocol overhead

Use HTTP when:

- **Development**: Quick testing and debugging
- **Firewall Restrictions**: Only HTTP/HTTPS allowed
- **Simple Deployments**: No need for custom protocol setup

#### Protocol Comparison


| Feature     | HTTP/HTTPS              | UMICP                        |
| ----------- | ----------------------- | ---------------------------- |
| Transport   | reqwest (standard HTTP) | umicp-core crate             |
| Performance | Standard                | Optimized for large payloads |
| Latency     | Standard                | Lower overhead               |
| Firewall    | Widely supported        | May require configuration    |
| Build Time  | Fast                    | Requires UMICP feature       |

### Master/Slave Configuration (Read/Write Separation)


Vectorizer supports **Master-Replica replication** for high availability and read scaling. The SDK provides **automatic routing** - writes go to master, reads are distributed across replicas.

#### Basic Setup


```rust
use vectorizer_rust_sdk::{VectorizerClient, ReadPreference};

// Configure with master and replicas - SDK handles routing automatically
let client = VectorizerClient::builder()
    .master("http://master-node:15002")
    .replica("http://replica1:15002")
    .replica("http://replica2:15002")
    .api_key("your-api-key")
    .read_preference(ReadPreference::Replica)
    .build()?;

// Writes automatically go to master
client.create_collection("documents", 768, Some(SimilarityMetric::Cosine)).await?;
client.insert_texts("documents", vec![
    BatchTextRequest {
        id: "doc1".to_string(),
        text: "Sample document".to_string(),
        metadata: Some(metadata),
    }
]).await?;

// Reads automatically go to replicas (load balanced)
let results = client.search_vectors("documents", &query_vector, 10).await?;
let collections = client.list_collections().await?;
```

#### Read Preferences


| Preference | Description | Use Case |
|------------|-------------|----------|
| `ReadPreference::Replica` | Route reads to replicas (round-robin) | Default for high read throughput |
| `ReadPreference::Master` | Route all reads to master | When you need read-your-writes consistency |
| `ReadPreference::Nearest` | Route to the node with lowest latency | Geo-distributed deployments |

#### Read-Your-Writes Consistency


For operations that need to immediately read what was just written:

```rust
// Option 1: Override read preference for specific operation
client.insert_texts("docs", vec![new_doc]).await?;
let result = client.get_vector_with_preference("docs", "doc_id", ReadPreference::Master).await?;

// Option 2: Use a scoped master context
client.with_master(|master_client| async {
    master_client.insert_texts("docs", vec![new_doc]).await?;
    master_client.get_vector("docs", "doc_id").await
}).await?;
```

#### Automatic Operation Routing


The SDK automatically classifies operations:

| Operation Type | Routed To | Methods |
|---------------|-----------|---------|
| **Writes** | Always Master | `insert_texts`, `insert_vectors`, `update_vector`, `delete_vector`, `create_collection`, `delete_collection` |
| **Reads** | Based on `ReadPreference` | `search_vectors`, `get_vector`, `list_collections`, `intelligent_search`, `semantic_search`, `hybrid_search` |

#### Standalone Mode (Single Node)


For development or single-node deployments:

```rust
// Single node - no replication
let client = VectorizerClient::new_with_api_key("http://localhost:15002", "your-api-key")?;
```

## API Endpoints


### ✅ Health & Monitoring


- `health_check()` - Server health and statistics
- `list_collections()` - List all available collections

### ✅ Collection Management


- `create_collection()` - Create new vector collection
- `get_collection_info()` - Get collection details (limited support)
- `delete_collection()` - Delete collection (limited support)

### ✅ Vector Operations


- `search_vectors()` - Semantic search with text queries
- `insert_texts()` - Batch text insertion (limited support)
- `get_vector()` - Retrieve individual vectors (limited support)

### ✅ Embedding (Future)


- `embed_text()` - Generate embeddings (endpoint not available)

## Tier demotion (issue #265)


Three methods cover the cortex consolidation-tier pruner pattern:
delete one vector, batch-delete by id, and move vectors between
collections without re-embedding.

```rust
use vectorizer_sdk::VectorizerClient;

let client = VectorizerClient::new(Default::default());

// Single delete.
client.delete_vector("hot", "vec-1").await?;

// Batch delete with per-id status.
let report = client
    .delete_vectors("hot", &vec!["vec-2".into(), "vec-3".into()])
    .await?;
println!("deleted={}, failed={}", report.deleted, report.failed);

// Tier demotion: move aged vectors hot → warm without re-embedding.
let aged: Vec<String> = collect_aged_ids().await?;
let mv = client
    .move_to_collection("hot", "warm", &aged)
    .await?;
for row in mv.results.iter().filter(|r| r.status != "ok") {
    eprintln!("move failed: id={:?} status={} err={:?}",
              row.id, row.status, row.error);
}
```

The `move_to_collection` server endpoint inserts into `dst` BEFORE
deleting from `src`. A mid-batch crash leaves a recoverable duplicate
(never data loss). Per-id outcomes (`ok | missing_in_src |
dst_insert_failed | src_delete_failed`) populate `MoveReport.results`
without aborting the batch.

## Control surface (3.4)

### Admin / observability


```rust
use vectorizer_sdk::VectorizerClient;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = VectorizerClient::new_default()?;

    // Server health, uptime, collection/vector counts
    let stats = client.get_stats().await?;
    println!("Total vectors: {}", stats.total_vectors);

    let status = client.get_status().await?;
    println!("Server v{}, uptime: {}s", status.version, status.uptime);

    // Recent logs
    let logs = client.get_logs(vectorizer_sdk::models::LogsQuery {
        lines: Some(50),
        level: Some("INFO".to_string()),
    }).await?;
    for entry in logs {
        println!("{}: {}", entry.timestamp, entry.message);
    }

    // Per-collection indexing progress
    let progress = client.get_indexing_progress().await?;
    for (collection, pct) in &progress.progress {
        println!("{}: {:.1}% complete", collection, pct);
    }

    // Force flush one collection
    client.force_save_collection("my_docs").await?;

    // List and clean empty collections
    let empty = client.list_empty_collections().await?;
    if !empty.is_empty() {
        let report = client.cleanup_empty_collections().await?;
        println!("Cleaned up {} empty collections", report.deleted);
    }

    // List workspaces
    let workspaces = client.list_workspaces().await?;
    println!("Workspaces: {:?}", workspaces);

    Ok(())
}
```

### Auth


```rust
use vectorizer_sdk::VectorizerClient;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = VectorizerClient::new_default()?;

    // Current user info
    let me = client.me().await?;
    println!("Logged in as: {} (roles: {:?})", me.username, me.roles);

    // Refresh token with extended TTL
    let new_token = client.refresh_token().await?;
    println!("Token refreshed, expires in: {} seconds", new_token.expires_in);

    // Validate password before creating account
    let report = client.validate_password("MySecure123!").await?;
    println!("Valid: {}, feedback: {:?}", report.valid, report.feedback);

    // Create API key for programmatic access
    let key_req = vectorizer_sdk::models::CreateApiKeyRequest {
        name: "integration-key".to_string(),
        expires_in: Some(86400 * 365), // 1 year
    };
    let api_key = client.create_api_key(key_req).await?;
    println!("API Key: {}", api_key.api_key.unwrap_or_default());

    // List and revoke API keys
    let keys = client.list_api_keys().await?;
    for key in keys {
        println!("Key: {} (expires: {})", key.id, key.expires_at);
    }
    client.revoke_api_key(&keys[0].id).await?;

    // Change password
    client.change_password("newPassword123!").await?;

    // Logout
    client.logout().await?;

    Ok(())
}
```

### Replication


```rust
use vectorizer_sdk::VectorizerClient;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = VectorizerClient::new_default()?;

    // Check replication role and status
    let status = client.get_replication_status().await?;
    println!("Role: {}, enabled: {}", status.role, status.enabled);

    // Get replication statistics (master/replica lag, sync status)
    let stats = client.get_replication_stats().await?;
    println!("Bytes synced: {}", stats.bytes_synced);

    // List all replicas connected to this master
    let replicas = client.list_replicas().await?;
    for replica in replicas {
        println!("Replica: {} (lag: {}ms)", replica.address, replica.lag_ms);
    }

    Ok(())
}
```

### Discovery pipeline


The discovery pipeline chains six stages from broad search to final LLM-ready prompt:

```rust
use vectorizer_sdk::VectorizerClient;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = VectorizerClient::new_default()?;

    // Stage 1: Broad discovery — multi-query search across all collections
    let broad_req = vectorizer_sdk::models::BroadDiscoveryRequest {
        query: "machine learning algorithms".to_string(),
        collections: None,
        max_results: Some(20),
    };
    let broad = client.broad_discovery(broad_req).await?;
    println!("Found {} broad results", broad.results.len());

    // Stage 2: Semantic focus — narrow search to top collection
    let focus_req = vectorizer_sdk::models::SemanticFocusRequest {
        query: "neural networks".to_string(),
        collection: "research".to_string(),
        max_results: Some(10),
    };
    let focused = client.semantic_focus(focus_req).await?;
    println!("Focused results: {}", focused.results.len());

    // Stage 3: Promote README — elevate high-quality chunks
    let promote_req = vectorizer_sdk::models::PromoteReadmeRequest {
        results: focused.results,
        readme_boost: Some(2.0),
    };
    let promoted = client.promote_readme(promote_req).await?;

    // Stage 4: Compress evidence — distill to bullet points
    let compress_req = vectorizer_sdk::models::CompressEvidenceRequest {
        chunks: promoted.results,
        max_bullets: Some(15),
    };
    let bullets = client.compress_evidence(compress_req).await?;
    println!("Evidence bullets: {:?}", bullets.bullets);

    // Stage 5: Build answer plan — organize bullets into sections
    let plan_req = vectorizer_sdk::models::AnswerPlanRequest {
        evidence: bullets.bullets,
        max_sections: Some(5),
    };
    let plan = client.build_answer_plan(plan_req).await?;
    println!("Sections: {:?}", plan.sections);

    // Stage 6: Render LLM prompt — final markdown string for LLM
    let prompt_req = vectorizer_sdk::models::RenderPromptRequest {
        plan,
        style: Some("formal".to_string()),
    };
    let llm_prompt = client.render_llm_prompt(prompt_req).await?;
    println!("LLM prompt:\n{}", llm_prompt.markdown);

    Ok(())
}
```

### Hub backups


```rust
use vectorizer_sdk::VectorizerClient;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = VectorizerClient::new_default()?;

    let user_id = "user-123";

    // List user's backups
    let backups = client.list_user_backups(user_id).await?;
    for backup in &backups {
        println!("Backup: {} (size: {} bytes)", backup.id, backup.size_bytes);
    }

    // Create a new backup
    let backup_req = vectorizer_sdk::models::CreateUserBackupRequest {
        user_id: user_id.to_string(),
        name: "full-backup-2024-01".to_string(),
        description: Some("January full backup".to_string()),
        collections: None, // backup all
    };
    let backup = client.create_user_backup(backup_req).await?;
    println!("Created backup: {}", backup.id);

    // Restore a backup
    let restore_req = vectorizer_sdk::models::RestoreUserBackupRequest {
        user_id: user_id.to_string(),
        backup_id: backup.id.clone(),
    };
    client.restore_user_backup(restore_req).await?;
    println!("Restore started");

    // Delete old backup
    client.delete_user_backup(user_id, &backups[0].id).await?;

    Ok(())
}
```

## Examples


Run the examples to see the SDK in action:

```bash
# Basic usage example

cargo run --example basic_example

# Comprehensive test suite (9/9 tests passing)

cargo run --example comprehensive_test
```

## Testing


The SDK includes comprehensive tests that verify:

- ✅ Client creation and configuration
- ✅ Health check functionality
- ✅ Collection listing and information
- ✅ Vector search operations
- ✅ Collection creation
- ✅ Error handling and edge cases

**Test Results: 9/9 endpoints functional (100% success rate)**

## Compatibility


- **Rust**: 1.90.0+ (Rust 2024 edition)
- **Vectorizer Server**: v0.20.0+
- **HTTP**: REST API with JSON payloads
- **UMICP**: Optional feature (enable with `--features umicp`)
- **Async Runtime**: Tokio 1.35+

## Building


### HTTP Only (Default)


```bash
cargo build --release
```

### With UMICP Support


```bash
cargo build --release --features umicp
```

### Run Tests


```bash
# HTTP tests only

cargo test

# UMICP tests

cargo test --features umicp

# Specific test

cargo test --test umicp_tests --features umicp
```

### Run Examples


```bash
# HTTP example

cargo run --example basic_example

# UMICP example (requires feature)

cargo run --example umicp_usage --features umicp
```

## Error Handling


The SDK provides comprehensive error types:

```rust
use vectorizer_rust_sdk::{VectorizerClient, VectorizerError};

match client.search_vectors("collection", "query", None, None).await {
    Ok(results) => println!("Found {} results", results.results.len()),
    Err(VectorizerError::Network(msg)) => eprintln!("Network error: {}", msg),
    Err(VectorizerError::Server(msg)) => eprintln!("Server error: {}", msg),
    Err(e) => eprintln!("Other error: {}", e),
}
```

## Qdrant Feature Parity


The SDK provides full compatibility with Qdrant 1.14.x REST API:

### Snapshots API


```rust
// List collection snapshots
let snapshots = client.qdrant_list_collection_snapshots("my_collection").await?;

// Create snapshot
let snapshot = client.qdrant_create_collection_snapshot("my_collection").await?;

// Delete snapshot
client.qdrant_delete_collection_snapshot("my_collection", "snapshot_name").await?;

// Recover from snapshot
client.qdrant_recover_collection_snapshot("my_collection", "snapshots/backup.snapshot").await?;

// Full snapshot (all collections)
let full_snapshot = client.qdrant_create_full_snapshot().await?;
```

### Sharding API


```rust
// List shard keys
let shard_keys = client.qdrant_list_shard_keys("my_collection").await?;

// Create shard key
let shard_config = serde_json::json!({"shard_key": "tenant_id"});
client.qdrant_create_shard_key("my_collection", &shard_config).await?;

// Delete shard key
client.qdrant_delete_shard_key("my_collection", &shard_config).await?;
```

### Cluster Management API


```rust
// Get cluster status
let status = client.qdrant_get_cluster_status().await?;

// Recover current peer
client.qdrant_cluster_recover().await?;

// Remove peer
client.qdrant_remove_peer("peer_123").await?;

// Metadata operations
let metadata_keys = client.qdrant_list_metadata_keys().await?;
let key_value = client.qdrant_get_metadata_key("my_key").await?;
let value = serde_json::json!({"config": "value"});
client.qdrant_update_metadata_key("my_key", &value).await?;
```

### Query API


```rust
// Basic query
let query_request = serde_json::json!({
    "query": [0.1, 0.2, 0.3, ...],
    "limit": 10,
    "with_payload": true
});
let results = client.qdrant_query_points("my_collection", &query_request).await?;

// Query with prefetch (multi-stage retrieval)
let prefetch_request = serde_json::json!({
    "prefetch": [
        {"query": [0.1, 0.2, ...], "limit": 100}
    ],
    "query": {"fusion": "rrf"},
    "limit": 10
});
let results = client.qdrant_query_points("my_collection", &prefetch_request).await?;

// Batch query
let batch_request = serde_json::json!({
    "searches": [
        {"query": [0.1, 0.2, ...], "limit": 5},
        {"query": [0.3, 0.4, ...], "limit": 5}
    ]
});
let results = client.qdrant_batch_query_points("my_collection", &batch_request).await?;

// Query groups
let groups_request = serde_json::json!({
    "query": [0.1, 0.2, ...],
    "group_by": "category",
    "group_size": 3,
    "limit": 10
});
let results = client.qdrant_query_points_groups("my_collection", &groups_request).await?;
```

### Search Groups & Matrix API


```rust
// Search groups
let search_groups_request = serde_json::json!({
    "vector": [0.1, 0.2, ...],
    "group_by": "category",
    "group_size": 3,
    "limit": 5
});
let groups = client.qdrant_search_points_groups("my_collection", &search_groups_request).await?;

// Search matrix pairs (pairwise similarity)
let matrix_request = serde_json::json!({
    "sample": 100,
    "limit": 500
});
let pairs = client.qdrant_search_matrix_pairs("my_collection", &matrix_request).await?;

// Search matrix offsets (compact format)
let offsets = client.qdrant_search_matrix_offsets("my_collection", &matrix_request).await?;
```

## Contributing


This SDK is ready for production use. All endpoints have been tested and verified functional.