Skip to content

Commit 2ac251f

Browse files
committed
Update Python client to support batch insert and search
1 parent 983c044 commit 2ac251f

10 files changed

Lines changed: 422 additions & 122 deletions

File tree

‎client/python/USAGE.md‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ async with AsyncVortexDB(
5656
payload=Payload.text("hello async vortex"),
5757
)
5858
```
59+
### Batch Insertion and Search Support
60+
61+
The client now supports batch insertion and batch search queries.
62+
Methods of usage and examples available in:
63+
```examples/batch_insert_usage.py``` & ```examples/search_query_usage.py```
5964

6065
---
6166

@@ -115,6 +120,22 @@ Raises
115120

116121
---
117122

123+
#### **Batch Insert**
124+
125+
Insert multiple vectors with payloads in a single request
126+
```
127+
batch_insert(*, items: list[tuple[DenseVector, Payload]]) -> list[str]
128+
```
129+
130+
Returns
131+
- List of `point_id` (UUID string)
132+
133+
Raises
134+
- `TypeError` if input structure is invalid
135+
- gRPC-mapped errors (see Error Handling)
136+
137+
---
138+
118139
#### **Get**
119140

120141
Fetch a point by its ID
@@ -149,6 +170,32 @@ Raises
149170

150171
---
151172

173+
#### **Batch Search**
174+
175+
Search for nearest neighbours for multiple queries in a single request
176+
```
177+
batch_search(
178+
*,
179+
queries,
180+
similarity: Similarity | None = None,
181+
limit: int | None = None,
182+
) -> list[list[str]]
183+
```
184+
185+
Returns
186+
- `TypeError` for invalid query formats
187+
- `ValueError` if required parameters are missing
188+
189+
Supported Input Formats:
190+
The `queries` parameter is flexible and supports multiple formats:
191+
- List of `SearchQuery` objects
192+
- List of `(DenseVector, Similarity, Limit)` tuples
193+
- List of `(DenseVector, Similarity)` tuples with a global `Limit`
194+
- List of `(DenseVector, Limit)` tuples with a global `Similarity`
195+
- List of `DenseVector` with global `Similarity` and `Limit`
196+
197+
---
198+
152199
#### **Delete**
153200

154201
Delete a point by its ID
@@ -214,6 +261,19 @@ All fields are directly accessible:
214261

215262
---
216263

264+
### `SearchQuery`
265+
266+
```
267+
SearchQuery(
268+
vector: DenseVector,
269+
similarity: Similarity,
270+
limit: int,
271+
)
272+
```
273+
Structured representation of a search request
274+
275+
---
276+
217277
### `Similarity`
218278

219279
Enum representing distance functions:

‎client/python/examples/async_usage.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
async def main():
77
async with AsyncVortexDB(
88
grpc_url="localhost:50051",
9-
api_key="your-api-key",
9+
api_key="my-secret-password",
1010
) as db:
1111
point_id = await db.insert(
1212
vector=DenseVector([0.1, 0.2, 0.3]),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from vortexdb import VortexDB
2+
from vortexdb import DenseVector, Payload, to_dense_vectors
3+
4+
5+
def main():
6+
db = VortexDB(
7+
grpc_url="localhost:50051",
8+
api_key="my-secret-password",
9+
)
10+
11+
raw_vectors = [
12+
[0.1, 0.2, 0.3],
13+
[0.4, 0.5, 0.6],
14+
[0.7, 0.8, 0.9],
15+
]
16+
vectors = to_dense_vectors(raw_vectors)
17+
18+
p1 = Payload.text("hello world")
19+
p2 = Payload.image("/img/a.png")
20+
p3 = Payload.text("foo bar")
21+
22+
items = [
23+
(vectors[0], p1),
24+
(vectors[1], p2),
25+
(vectors[2], p3),
26+
]
27+
28+
# Batch Insert
29+
point_ids = db.batch_insert(items=items)
30+
print("Inserted ids:\n", point_ids)
31+
32+
for pid in point_ids:
33+
db.delete(point_id=pid)
34+
35+
db.close()
36+
37+
38+
if __name__ == "__main__":
39+
main()
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from vortexdb import VortexDB
2+
from vortexdb import DenseVector, Similarity, SearchQuery, to_dense_vectors
3+
4+
5+
def main():
6+
db = VortexDB(
7+
grpc_url="localhost:50051",
8+
api_key="my-secret-password",
9+
)
10+
11+
raw_vectors = [
12+
[0.1, 0.2, 0.3],
13+
[0.4, 0.5, 0.6],
14+
[0.7, 0.8, 0.9],
15+
]
16+
vectors = to_dense_vectors(raw_vectors)
17+
18+
q = SearchQuery(
19+
vector=vectors[0],
20+
similarity=Similarity.COSINE,
21+
limit=3,
22+
)
23+
res = db.search(query=q)
24+
print("Single SearchQuery:\n", res)
25+
26+
# List of SearchQuery
27+
queries = [
28+
SearchQuery(vectors[0], Similarity.HAMMING, 3),
29+
SearchQuery(vectors[1], Similarity.EUCLIDEAN, 2),
30+
q,
31+
]
32+
res = db.batch_search(queries=queries)
33+
print("\nBatch SearchQuery:\n", res)
34+
35+
# List of vectors with global Similarity and Limit
36+
res = db.batch_search(
37+
queries=vectors,
38+
similarity=Similarity.COSINE,
39+
limit=3,
40+
)
41+
print("\nList of DenseVectors:\n", res)
42+
43+
# List of tuple (DenseVector, Similarity) with global Limit
44+
queries = [
45+
(vectors[0], Similarity.COSINE),
46+
(vectors[1], Similarity.MANHATTAN),
47+
]
48+
res = db.batch_search(
49+
queries=queries,
50+
limit=3,
51+
)
52+
print("\nList of (DenseVector, Similarity):\n", res)
53+
54+
# List of tuple (DenseVector, Limit) with global Similarity
55+
queries = [
56+
(vectors[0], 2),
57+
(vectors[1], 4),
58+
]
59+
res = db.batch_search(
60+
queries=queries,
61+
similarity=Similarity.COSINE,
62+
)
63+
print("\nList of (DenseVector, Limit):\n", res)
64+
65+
db.close()
66+
67+
68+
if __name__ == "__main__":
69+
main()

‎client/python/pyproject.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ classifiers = [
2424
]
2525

2626
dependencies = [
27-
"grpcio>=1.60",
28-
"protobuf>=4.25",
27+
"grpcio>=1.81.1",
28+
"protobuf>=6.33.5,<7.0.0",
2929
]
3030

3131
[project.optional-dependencies]
3232
dev = [
33-
"grpcio-tools>=1.60",
33+
"grpcio-tools>=1.81.1,<2.0.0",
3434
"pytest>=7.0",
3535
]
3636

0 commit comments

Comments
 (0)