Commit e32e74e
authored
feat: Support S3 Vectors (#3330)
* feat: Support S3 Vectors
Bring Amazon S3 Vectors — AWS's native, cost-optimised vector store
for similarity search, RAG, and AI agents — to AWS SDK for pandas.
With this change, indexing a DataFrame and running an approximate-
nearest-neighbour query is a one-liner; on-the-fly embedding via
Amazon Bedrock is built in.
Implementation lives in a private subpackage `awswrangler/s3/_vectors/`
and is re-exported flat on `wr.s3.*`, matching the s3_tables convention.
Public surface (14 functions on `wr.s3`):
- Buckets: create_vector_bucket, delete_vector_bucket,
list_vector_buckets, get_vector_bucket
- Indexes: create_vector_index, delete_vector_index,
list_vector_indexes, get_vector_index
- Data: put_vectors, put_vectors_from_df, get_vectors,
delete_vectors, list_vectors, query_vectors
Highlights:
- End-to-end RAG: pass `text_column` + `bedrock_model_id` to
put_vectors_from_df and awswrangler embeds each row via Bedrock
(Titan / Cohere) and writes the resulting vectors plus all other
columns as filterable metadata. query_vectors mirrors this with
`query_text` / `query_vector`.
- MongoDB-style metadata filters ($eq, $ne, $gt, $gte, $lt, $lte,
$in, $nin, $exists, $and, $or) evaluated server-side during search.
- Automatic chunking to AWS API limits (500/put, 100/get, 500/delete)
and parallel-segment list_vectors (up to 16 segments).
- Float32 coercion + non-finite rejection; NaN / pd.NA / None
metadata cells dropped per row.
* test: add mocked unit tests and live integration tests for S3 Vectors
- tests/unit/test_s3_vectors_mocked.py — 46 tests using unittest.mock,
no AWS required. Covers chunking, target resolution, float32 coercion,
NaN/pd.NA metadata drop, parallel-segment list, query top-k bounds,
Bedrock Titan/Cohere request and response shapes, and aliasing identity.
- tests/unit/test_s3_vectors.py — 10 live integration tests using new
vector_bucket (session-scope) and vector_index (function-scope)
fixtures in tests/conftest.py. Fixtures self-bootstrap via
create_vector_bucket / create_vector_index; no CDK stack required.
* docs: api reference and tutorial for S3 Vectors
- docs/source/api.rst: new "Amazon S3 Vectors" section after
"Amazon S3 Tables", listing all 14 public functions.
- tutorials/043 - Amazon S3 Vectors.ipynb: end-to-end walkthrough
covering bucket/index lifecycle, discovery, Bedrock-embedded writes,
semantic queries with metadata filters, per-key CRUD, bulk export,
and cleanup.
- README.md: tutorial 043 entry.
* fix: type-parametrize np.ndarray for mypy on Python 3.10
* fix: use hyphen in vector index fixture name (underscore is invalid)
* fix: avoid zero-norm vectors in live integration tests (cosine rejects them)
* feat: add `chunked` parameter to list_vectors
Memory-friendly streaming for indexes too large to materialise in one
DataFrame. Mirrors the `chunked: bool | int` convention used by
`s3.read_parquet` and `athena.read_sql_query`:
- chunked=False (default) — unchanged; returns a DataFrame and keeps
the parallel-segment fan-out (up to 16 segments).
- chunked=True — yields one DataFrame per underlying API page.
- chunked=INTEGER — yields DataFrames of exactly N rows (final frame
may be shorter).
Chunked streaming is single-segment and sequential by design;
`use_threads` is ignored in that mode, since lazy iteration across
parallel segments would require buffering and defeat the memory win.
Internally, `_list_segment` is now a thin materialiser around a new
`_iter_list_pages` generator, so the per-segment pagination logic
(including `max_items` enforcement across pages) is shared by both the
eager and streaming paths.
Tests: 4 new cases cover per-page yield, exact-size chunking, laziness
(no API call before the first `next()`), and `max_items` truncation of
the chunked stream.1 parent 7ab4b55 commit e32e74e
16 files changed
Lines changed: 2814 additions & 4 deletions
File tree
- awswrangler
- s3
- _vectors
- docs/source
- tests
- unit
- tutorials
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
24 | 40 | | |
25 | 41 | | |
26 | 42 | | |
| |||
71 | 87 | | |
72 | 88 | | |
73 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
74 | 104 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments