-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrebuild-with-vectors.sh
More file actions
executable file
Β·182 lines (158 loc) Β· 5.22 KB
/
rebuild-with-vectors.sh
File metadata and controls
executable file
Β·182 lines (158 loc) Β· 5.22 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
set -e
echo "π PHASE 6 - DAY 1: Rebuilding Indexes with Vector Embeddings"
echo "=============================================================="
echo ""
# Configuration
OLLAMA_URL="http://localhost:11434"
BATCH_SIZE=100
SKIP_VECTORS=false
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--skip-vectors)
SKIP_VECTORS=true
shift
;;
--batch-size)
BATCH_SIZE="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--skip-vectors] [--batch-size N]"
exit 1
;;
esac
done
# Step 1: Verify Ollama is running
echo "1οΈβ£ Checking Ollama availability..."
if ! curl -s "$OLLAMA_URL/api/tags" > /dev/null 2>&1; then
echo "β Ollama not reachable at $OLLAMA_URL"
echo " Start it with: docker compose -f docker-compose.yml up -d ollama"
exit 1
fi
echo "β
Ollama is running"
echo ""
# Step 2: Verify all-minilm model is downloaded
echo "2οΈβ£ Checking all-minilm model..."
if ! docker exec ollama ollama list | grep -q "all-minilm"; then
echo "β¬οΈ Downloading all-minilm model..."
docker exec ollama ollama pull all-minilm
else
echo "β
all-minilm model ready"
fi
echo ""
# Step 3: Backup old indexes
echo "3οΈβ£ Backing up old indexes..."
BACKUP_DIR="search-backup-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$BACKUP_DIR"
for i in {0..7}; do
if [ -d "search.bleve-$i" ]; then
echo " Backing up search.bleve-$i β $BACKUP_DIR/"
cp -r "search.bleve-$i" "$BACKUP_DIR/"
fi
done
echo "β
Backup complete: $BACKUP_DIR/"
echo ""
# Step 4: Remove old indexes
echo "4οΈβ£ Removing old indexes..."
for i in {0..7}; do
if [ -d "search.bleve-$i" ]; then
rm -rf "search.bleve-$i"
echo " Removed search.bleve-$i"
fi
done
echo "β
Old indexes removed"
echo ""
# Step 5: Build indexer
echo "5οΈβ£ Building vector-enabled indexer..."
go build -o indexer-vector cmd/indexer/main.go
echo "β
Indexer built: ./indexer-vector"
echo ""
# Step 6: Index all shards with embeddings
echo "6οΈβ£ Indexing shards with vector embeddings..."
echo " (This will take ~5-10 minutes for 24k docs)"
echo ""
START_TIME=$(date +%s)
for i in {0..7}; do
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo " SHARD $i: Starting..."
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββ"
SHARD_START=$(date +%s)
if [ "$SKIP_VECTORS" = true ]; then
./indexer-vector \
-input="shard-$i.jsonl" \
-index="search.bleve" \
-shard-id="$i" \
-batch-size="$BATCH_SIZE" \
-ollama="$OLLAMA_URL" \
-skip-vectors
else
./indexer-vector \
-input="shard-$i.jsonl" \
-index="search.bleve" \
-shard-id="$i" \
-batch-size="$BATCH_SIZE" \
-ollama="$OLLAMA_URL"
fi
SHARD_END=$(date +%s)
SHARD_ELAPSED=$((SHARD_END - SHARD_START))
# Check index was created
if [ -d "search.bleve-$i" ]; then
SIZE=$(du -sh "search.bleve-$i" | cut -f1)
echo "β
Shard $i complete: $SIZE (${SHARD_ELAPSED}s)"
else
echo "β Shard $i FAILED: index not created"
exit 1
fi
echo ""
done
END_TIME=$(date +%s)
TOTAL_ELAPSED=$((END_TIME - START_TIME))
MINUTES=$((TOTAL_ELAPSED / 60))
SECONDS=$((TOTAL_ELAPSED % 60))
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β
ALL SHARDS INDEXED"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Step 7: Summary
echo "π SUMMARY:"
echo " Total time: ${MINUTES}m ${SECONDS}s"
echo " Shards: 8"
echo " Documents: ~24,765"
if [ "$SKIP_VECTORS" = false ]; then
echo " Embeddings: ~24,765 Γ 384 dims"
fi
echo ""
# Show index sizes
echo "π Index Sizes:"
for i in {0..7}; do
if [ -d "search.bleve-$i" ]; then
SIZE=$(du -sh "search.bleve-$i" | cut -f1)
DOCS=$(cat "shard-$i.jsonl" | wc -l)
printf " shard-%d: %8s (%5d docs)\n" "$i" "$SIZE" "$DOCS"
fi
done
echo ""
# Step 8: Restart services
echo "7οΈβ£ Restarting shard services..."
if docker compose -f docker-compose.yml ps shard-0 > /dev/null 2>&1; then
echo " Stopping shards..."
docker compose -f docker-compose.yml stop shard-{0..7}
echo " Starting shards with new indexes..."
docker compose -f docker-compose.yml up -d shard-{0..7}
echo "β
Shards restarted"
else
echo "βοΈ Docker services not running (skipping restart)"
fi
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "π PHASE 6 DAY 1 COMPLETE!"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo "Next steps:"
echo " 1. Test vector retrieval: ./test-vectors.sh"
echo " 2. Verify embeddings: curl 'localhost:8090/search?q=test'"
echo " 3. Ready for Day 2: True semantic search!"
echo ""