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
"""BitPolar gRPC Client — connect to the BitPolar compression service.
The gRPC server provides language-agnostic access to BitPolar quantization.
Any language with gRPC support can compress, decompress, and search vectors.
Prerequisites:
pip install grpcio grpcio-tools numpy
# Start server: cargo run -p bitpolar-server
Usage:
python examples/python/10_grpc_client.py
"""
# Example client code (requires running server):
#
# import grpc
# from bitpolar.v1 import service_pb2, service_pb2_grpc
#
# channel = grpc.insecure_channel('localhost:50051')
# stub = service_pb2_grpc.VectorCompressionStub(channel)
#
# # Encode vectors
# vectors = np.random.randn(100, 384).astype(np.float32).flatten().tolist()
# response = stub.Encode(service_pb2.EncodeRequest(
# vectors=vectors, dim=384, count=100, bits=4, seed=42
# ))
# print(f"Compressed {response.original_size}B → {response.compressed_size}B")
#
# # Add vectors to index
# ids = list(range(100))
# stub.AddVectors(service_pb2.AddVectorsRequest(
# ids=ids, vectors=vectors, dim=384
# ))
#
# # Search
# query = np.random.randn(384).astype(np.float32).tolist()
# results = stub.Search(service_pb2.SearchRequest(query=query, k=10))
# for r in results.results:
# print(f" ID={r.id}, score={r.score:.4f}")
#
# # Health check
# health = stub.Health(service_pb2.HealthRequest())
# print(f"Status: {health.status}, index_size: {health.index_size}")