Skip to content

Instantly share code, notes, and snippets.

@yuvalif
Created June 1, 2026 19:28
Show Gist options
  • Select an option

  • Save yuvalif/69e7f1fb8ec35fcdb810841403905ea2 to your computer and use it in GitHub Desktop.

Select an option

Save yuvalif/69e7f1fb8ec35fcdb810841403905ea2 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
RGW_ENDPOINT="http://localhost:8000"
VECTOR_BUCKET="demo-vector-bucket"
INDEX_NAME="demo-index"
DIMENSION=4
# --------------------------------------------------------------------------
# 1. Create a Vector Bucket
# --------------------------------------------------------------------------
aws --endpoint-url $RGW_ENDPOINT s3vectors create-vector-bucket \
--vector-bucket-name "$VECTOR_BUCKET" | jq .
# --------------------------------------------------------------------------
# 2. Create an Index
# --------------------------------------------------------------------------
aws --endpoint-url $RGW_ENDPOINT s3vectors create-index \
--vector-bucket-name "$VECTOR_BUCKET" \
--index-name "$INDEX_NAME" \
--data-type float32 \
--dimension $DIMENSION \
--distance-metric cosine | jq .
# --------------------------------------------------------------------------
# 3. Upload 20 vectors
# --------------------------------------------------------------------------
VECTORS="["
for i in $(seq 1 20); do
v1="0.$((i * 17 % 100))"
v2="0.$((i * 31 % 100))"
v3="0.$((i * 47 % 100))"
v4="0.$((i * 61 % 100))"
ENTRY="{\"key\": \"vec-$(printf '%03d' $i)\", \"data\": {\"float32\": [$v1, $v2, $v3, $v4]}, \"metadata\": \"{\\\"label\\\": \\\"item-$i\\\"}\"}"
if [ "$i" -lt 20 ]; then
ENTRY="$ENTRY,"
fi
VECTORS="$VECTORS $ENTRY"
done
VECTORS="$VECTORS ]"
aws --endpoint-url $RGW_ENDPOINT s3vectors put-vectors \
--vector-bucket-name "$VECTOR_BUCKET" \
--index-name "$INDEX_NAME" \
--vectors "$VECTORS"
# --------------------------------------------------------------------------
# 4. Query vectors _ find top 10 nearest to a probe vector
# --------------------------------------------------------------------------
aws --endpoint-url $RGW_ENDPOINT s3vectors query-vectors \
--vector-bucket-name "$VECTOR_BUCKET" \
--index-name "$INDEX_NAME" \
--query-vector '{"float32": [0.5, 0.5, 0.5, 0.5]}' \
--top-k 10 \
--return-metadata \
--return-distance | jq .
# --------------------------------------------------------------------------
# 5. List all vectors in the index
# --------------------------------------------------------------------------
RESULT=$(aws --endpoint-url $RGW_ENDPOINT s3vectors list-vectors \
--vector-bucket-name "$VECTOR_BUCKET" \
--index-name "$INDEX_NAME" \
--return-metadata \
--return-data)
echo "$RESULT" | jq .
KEYS=$(echo "$RESULT" | jq -r '[.vectors[].key]')
echo "Found $(echo "$KEYS" | jq 'length') vectors to delete"
# --------------------------------------------------------------------------
# 6. Delete vectors based on the list
# --------------------------------------------------------------------------
aws --endpoint-url $RGW_ENDPOINT s3vectors delete-vectors \
--vector-bucket-name "$VECTOR_BUCKET" \
--index-name "$INDEX_NAME" \
--keys "$KEYS"
# --------------------------------------------------------------------------
# 7. Delete the index
# --------------------------------------------------------------------------
aws --endpoint-url $RGW_ENDPOINT s3vectors delete-index \
--vector-bucket-name "$VECTOR_BUCKET" \
--index-name "$INDEX_NAME"
# --------------------------------------------------------------------------
# 8. Delete the vector bucket
# --------------------------------------------------------------------------
aws --endpoint-url $RGW_ENDPOINT s3vectors delete-vector-bucket \
--vector-bucket-name "$VECTOR_BUCKET"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment