-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·122 lines (109 loc) · 4.09 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·122 lines (109 loc) · 4.09 KB
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
#!/bin/bash
# Standard S3 Vectors setup script.
# - Creates (or reuses) a vector bucket
# - Creates (or reuses) an index
#
# Usage:
# ./setup.sh
# AWS_PROFILE=default AWS_REGION=us-east-1 VECTOR_BUCKET_NAME=my-bucket INDEX_NAME=documents ./setup.sh
set -euo pipefail
# ------------------------------------------------------------
# Configuration (override via environment variables)
# ------------------------------------------------------------
VECTOR_BUCKET_NAME="${VECTOR_BUCKET_NAME:-bucket-vector-s3-lambda}"
INDEX_NAME="${INDEX_NAME:-documents}"
DATA_TYPE="${DATA_TYPE:-float32}"
DIMENSION="${DIMENSION:-768}"
DISTANCE_METRIC="${DISTANCE_METRIC:-cosine}"
AWS_REGION="${AWS_REGION:-us-east-1}"
AWS_PROFILE="${AWS_PROFILE:-default}"
# Match the metadata keys inserted by ingestion (`data-ingestion/src/app.ts`).
# Note: JSON form is used to support keys like "doc_id" and "sections".
METADATA_CONFIGURATION_JSON='{"nonFilterableMetadataKeys":["type","doc_id","key","product","sections","keywords","id","text"]}'
echo "=========================================="
echo "S3 Vectors Setup"
echo "=========================================="
echo "Bucket Name: $VECTOR_BUCKET_NAME"
echo "Index Name: $INDEX_NAME"
echo "Region: $AWS_REGION"
echo "Profile: $AWS_PROFILE"
echo "Dimension: $DIMENSION"
echo "Metric: $DISTANCE_METRIC"
echo "=========================================="
echo ""
# ------------------------------------------------------------
# Step 1: Create Vector Bucket (idempotent)
# ------------------------------------------------------------
echo "Step 1/2: Creating S3 Vector Bucket..."
if aws s3vectors create-vector-bucket \
--vector-bucket-name "$VECTOR_BUCKET_NAME" \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE" 2>&1; then
echo "✓ Vector bucket created successfully"
else
if aws s3vectors list-vector-buckets \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE" 2>&1 | grep -q "$VECTOR_BUCKET_NAME"; then
echo "⚠ Vector bucket already exists, continuing..."
else
echo "✗ Failed to create vector bucket"
exit 1
fi
fi
echo ""
# ------------------------------------------------------------
# Step 2: Create Index (idempotent)
# ------------------------------------------------------------
echo "Step 2/2: Creating Vector Index..."
if aws s3vectors create-index \
--vector-bucket-name "$VECTOR_BUCKET_NAME" \
--index-name "$INDEX_NAME" \
--data-type "$DATA_TYPE" \
--dimension "$DIMENSION" \
--distance-metric "$DISTANCE_METRIC" \
--metadata-configuration "$METADATA_CONFIGURATION_JSON" \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE" 2>&1; then
echo "✓ Vector index created successfully"
else
ERROR_MSG=$(aws s3vectors create-index \
--vector-bucket-name "$VECTOR_BUCKET_NAME" \
--index-name "$INDEX_NAME" \
--data-type "$DATA_TYPE" \
--dimension "$DIMENSION" \
--distance-metric "$DISTANCE_METRIC" \
--metadata-configuration "$METADATA_CONFIGURATION_JSON" \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE" 2>&1 || true)
if echo "$ERROR_MSG" | grep -qi "already exists"; then
echo "⚠ Vector index already exists, continuing..."
else
echo "✗ Failed to create vector index"
echo "$ERROR_MSG"
exit 1
fi
fi
echo ""
echo "=========================================="
echo "Setup Complete!"
echo "=========================================="
echo ""
echo "Vector Bucket ARN:"
aws s3vectors list-vector-buckets \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE" \
--query "VectorBuckets[?VectorBucketName=='$VECTOR_BUCKET_NAME'].VectorBucketArn" \
--output text 2>/dev/null || echo "Unable to retrieve ARN"
echo ""
echo "Index ARN:"
aws s3vectors list-indexes \
--vector-bucket-name "$VECTOR_BUCKET_NAME" \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE" \
--query "Indexes[?IndexName=='$INDEX_NAME'].IndexArn" \
--output text 2>/dev/null || echo "Unable to retrieve ARN"
echo ""
echo "Terraform hint (infra/terraform.tfvars):"
echo "vector_bucket_name = \"$VECTOR_BUCKET_NAME\""
echo "vector_bucket_index_name = \"$INDEX_NAME\""
echo "vector_bucket_index_arn = \"<INDEX_ARN_FROM_ABOVE>\""