parse-stack-next 5.5.3 → 5.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -4
- data/README.md +26 -13
- data/bin/parse-console +9 -1
- data/docs/TEST_SERVER.md +115 -238
- data/docs/mcp_guide.md +1 -1
- data/docs/mongodb_index_optimization_guide.md +3 -2
- data/docs/usage_guide.md +1 -1
- data/docs/yard-template/default/fulldoc/html/css/common.css +52 -9
- data/docs/yard-template/default/fulldoc/html/css/full_list.css +40 -13
- data/lib/parse/agent/constraint_translator.rb +18 -18
- data/lib/parse/agent/errors.rb +29 -7
- data/lib/parse/agent/metadata_dsl.rb +6 -6
- data/lib/parse/agent/tools.rb +250 -59
- data/lib/parse/agent.rb +42 -30
- data/lib/parse/api/aggregate.rb +3 -3
- data/lib/parse/api/cloud_functions.rb +19 -10
- data/lib/parse/api/objects.rb +8 -8
- data/lib/parse/api/users.rb +9 -9
- data/lib/parse/atlas_search/session.rb +34 -34
- data/lib/parse/atlas_search.rb +243 -110
- data/lib/parse/client/body_builder.rb +10 -10
- data/lib/parse/client/logging.rb +5 -2
- data/lib/parse/client/profiling.rb +5 -2
- data/lib/parse/client/protocol.rb +1 -1
- data/lib/parse/client/url_redaction.rb +94 -0
- data/lib/parse/client.rb +43 -28
- data/lib/parse/embeddings/image_fetch.rb +6 -1
- data/lib/parse/embeddings/voyage.rb +16 -17
- data/lib/parse/live_query/client.rb +7 -7
- data/lib/parse/live_query/subscription.rb +1 -1
- data/lib/parse/lock.rb +1 -1
- data/lib/parse/lock_backend.rb +118 -2
- data/lib/parse/model/acl.rb +24 -24
- data/lib/parse/model/classes/job_schedule.rb +8 -8
- data/lib/parse/model/classes/job_status.rb +9 -9
- data/lib/parse/model/classes/role.rb +49 -49
- data/lib/parse/model/classes/session.rb +2 -2
- data/lib/parse/model/classes/user.rb +66 -66
- data/lib/parse/model/core/builder.rb +7 -7
- data/lib/parse/model/core/create_lock.rb +1 -1
- data/lib/parse/model/core/properties.rb +4 -4
- data/lib/parse/model/file.rb +57 -16
- data/lib/parse/model/model.rb +19 -19
- data/lib/parse/model/object.rb +38 -38
- data/lib/parse/model/pointer.rb +4 -4
- data/lib/parse/model/push.rb +5 -5
- data/lib/parse/mongodb.rb +84 -26
- data/lib/parse/pipeline_security.rb +2 -2
- data/lib/parse/query/constraints.rb +38 -38
- data/lib/parse/query.rb +151 -75
- data/lib/parse/retrieval/reranker/cohere.rb +30 -0
- data/lib/parse/schema.rb +1 -1
- data/lib/parse/stack/version.rb +1 -1
- data/lib/parse/stack.rb +23 -10
- data/lib/parse/two_factor_auth/user_extension.rb +25 -25
- data/lib/parse/webhooks/payload.rb +35 -35
- data/lib/parse/webhooks/registration.rb +2 -2
- data/lib/parse/webhooks/replay_protection.rb +16 -16
- data/lib/parse/webhooks.rb +11 -11
- data/parse-stack-next.gemspec +19 -1
- metadata +2 -38
- data/.bundle/config +0 -5
- data/.env.sample +0 -138
- data/.env.test +0 -10
- data/.github/ISSUE_TEMPLATE/bug_report.yml +0 -105
- data/.github/ISSUE_TEMPLATE/feature_request.yml +0 -67
- data/.github/dependabot.yml +0 -13
- data/.github/workflows/codeql.yml +0 -44
- data/.github/workflows/docs.yml +0 -39
- data/.github/workflows/release.yml +0 -43
- data/.github/workflows/ruby.yml +0 -38
- data/.gitignore +0 -56
- data/.ruby-version +0 -1
- data/.solargraph.yml +0 -22
- data/.vscode/settings.json +0 -3
- data/.yardopts +0 -19
- data/Gemfile +0 -43
- data/Gemfile.lock +0 -198
- data/Makefile +0 -63
- data/Rakefile +0 -825
- data/config/parse-config.json +0 -12
- data/scripts/debug-ips.js +0 -35
- data/scripts/docker/Dockerfile.parse +0 -17
- data/scripts/docker/atlas-init.js +0 -284
- data/scripts/docker/docker-compose.atlas.yml +0 -80
- data/scripts/docker/docker-compose.test.yml +0 -159
- data/scripts/docker/docker-compose.verifyemail.yml +0 -4
- data/scripts/docker/mongo-init.js +0 -21
- data/scripts/docker/preflight.sh +0 -76
- data/scripts/eval_mcp_with_lm_studio.rb +0 -274
- data/scripts/start-parse.sh +0 -154
- data/scripts/start_mcp_server.rb +0 -78
- data/scripts/test_server_connection.rb +0 -82
- data/scripts/vector_prototype/create_vector_index.js +0 -105
- data/scripts/vector_prototype/fetch_embeddings.py +0 -241
- data/scripts/vector_prototype/fixture_manifest.json +0 -9
- data/scripts/vector_prototype/query_prototype.rb +0 -84
- data/scripts/vector_prototype/run.sh +0 -34
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// Atlas $vectorSearch index for vector_prototype.WikiArticle.
|
|
2
|
-
//
|
|
3
|
-
// Idempotent: drops any existing search indexes on the collection before
|
|
4
|
-
// creating the canonical one. Naming follows vector_rag_plan.md §3:
|
|
5
|
-
//
|
|
6
|
-
// <table>_<field>_<provider>_<dimensions>_idx
|
|
7
|
-
//
|
|
8
|
-
// Reused by both Parse::VectorSearch tests (v4.3) and Parse::Retrieval
|
|
9
|
-
// tests (v4.4). The collection's data is loaded separately by
|
|
10
|
-
// fetch_embeddings.py.
|
|
11
|
-
//
|
|
12
|
-
// Run:
|
|
13
|
-
// mongosh "mongodb://localhost:29020/vector_prototype?directConnection=true" \
|
|
14
|
-
// scripts/vector_prototype/create_vector_index.js
|
|
15
|
-
//
|
|
16
|
-
// To switch to 1024-dim (voyage-multimodal-3 compat), set DIMS=1024
|
|
17
|
-
// before running. Mongosh exposes shell args via passthroughs only,
|
|
18
|
-
// so the value is read from an env shim or edit the constant below.
|
|
19
|
-
|
|
20
|
-
// Read the manifest written by fetch_embeddings.py so dims/provider/name
|
|
21
|
-
// can't drift from the loaded data. mongosh runs on Node, so use fs.
|
|
22
|
-
const fs = require("fs");
|
|
23
|
-
const path = require("path");
|
|
24
|
-
const _scriptDir = path.dirname(typeof __filename !== "undefined" ? __filename : process.argv[1] || ".");
|
|
25
|
-
const _manifestPath = path.join(_scriptDir, "fixture_manifest.json");
|
|
26
|
-
const MANIFEST = JSON.parse(fs.readFileSync(_manifestPath, "utf8"));
|
|
27
|
-
|
|
28
|
-
const COLL = MANIFEST.collection;
|
|
29
|
-
const DIMS = MANIFEST.dims;
|
|
30
|
-
const PROVIDER = MANIFEST.provider;
|
|
31
|
-
const INDEX_NAME = MANIFEST.index_name;
|
|
32
|
-
|
|
33
|
-
print(`[idx] target: ${db.getName()}.${COLL} → ${INDEX_NAME}`);
|
|
34
|
-
|
|
35
|
-
// Drop any stale search indexes so re-runs converge to a known state.
|
|
36
|
-
try {
|
|
37
|
-
const existing = db[COLL].getSearchIndexes();
|
|
38
|
-
existing.forEach(function (i) {
|
|
39
|
-
print(` drop existing index: ${i.name}`);
|
|
40
|
-
db[COLL].dropSearchIndex(i.name);
|
|
41
|
-
});
|
|
42
|
-
} catch (e) {
|
|
43
|
-
print(` (no existing indexes / error listing: ${e.message})`);
|
|
44
|
-
}
|
|
45
|
-
sleep(1000);
|
|
46
|
-
|
|
47
|
-
print(`[idx] creating ${INDEX_NAME} (vectorSearch, ${DIMS} dims, cosine)`);
|
|
48
|
-
db[COLL].createSearchIndex(INDEX_NAME, "vectorSearch", {
|
|
49
|
-
fields: [
|
|
50
|
-
{
|
|
51
|
-
type: "vector",
|
|
52
|
-
path: "embedding",
|
|
53
|
-
numDimensions: DIMS,
|
|
54
|
-
similarity: "cosine",
|
|
55
|
-
},
|
|
56
|
-
// Filter fields — declare here anything you want to use as a
|
|
57
|
-
// $vectorSearch filter constraint. Atlas only accepts filter
|
|
58
|
-
// predicates on fields declared as type:"filter" in the index.
|
|
59
|
-
{ type: "filter", path: "wiki_id" },
|
|
60
|
-
],
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
print("[idx] waiting for queryable...");
|
|
64
|
-
let attempts = 0;
|
|
65
|
-
const maxAttempts = 60;
|
|
66
|
-
while (attempts < maxAttempts) {
|
|
67
|
-
const found = db[COLL].getSearchIndexes().find(function (i) {
|
|
68
|
-
return i.name === INDEX_NAME;
|
|
69
|
-
});
|
|
70
|
-
if (found && found.queryable === true) {
|
|
71
|
-
print(`[idx] ready after ${attempts * 2}s`);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
sleep(2000);
|
|
75
|
-
attempts++;
|
|
76
|
-
}
|
|
77
|
-
if (attempts >= maxAttempts) {
|
|
78
|
-
print("[idx] WARNING: index not queryable yet; later queries may fail");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Smoke-test: pick an arbitrary doc and find its top-5 neighbours.
|
|
82
|
-
print("\n[smoke] $vectorSearch self-similarity check");
|
|
83
|
-
const seed = db[COLL].findOne({});
|
|
84
|
-
if (!seed) {
|
|
85
|
-
print("[smoke] no docs loaded — run fetch_embeddings.py first");
|
|
86
|
-
} else {
|
|
87
|
-
const out = db[COLL].aggregate([
|
|
88
|
-
{
|
|
89
|
-
$vectorSearch: {
|
|
90
|
-
index: INDEX_NAME,
|
|
91
|
-
path: "embedding",
|
|
92
|
-
queryVector: seed.embedding,
|
|
93
|
-
numCandidates: 100,
|
|
94
|
-
limit: 5,
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
{ $project: { _id: 1, title: 1, _vscore: { $meta: "vectorSearchScore" } } },
|
|
98
|
-
]).toArray();
|
|
99
|
-
print(` seed: ${seed.title}`);
|
|
100
|
-
out.forEach(function (r, i) {
|
|
101
|
-
print(` ${i + 1}. score=${r._vscore.toFixed(4)} ${r.title}`);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
print("\n[done]");
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Vector-search & RAG test fixture loader.
|
|
4
|
-
|
|
5
|
-
Pulls a subset of a pre-computed embeddings dataset from HuggingFace and
|
|
6
|
-
loads it into Atlas Local at localhost:29020 (the same container managed
|
|
7
|
-
by scripts/docker/docker-compose.atlas.yml). Designed to be reused by both:
|
|
8
|
-
|
|
9
|
-
1. Vector search integration tests (Parse::VectorSearch — v4.3 plan)
|
|
10
|
-
2. RAG retrieval tests (Parse::Retrieval — v4.4 plan)
|
|
11
|
-
|
|
12
|
-
The Wikipedia article shape (title + full text + url + embedding) covers
|
|
13
|
-
both surfaces: vector tests need (title, embedding), RAG/chunking tests
|
|
14
|
-
need the full text body.
|
|
15
|
-
|
|
16
|
-
The runtime target is voyage-multimodal-3 (1024-dim) — the production
|
|
17
|
-
preference. The fixture data is provider-agnostic: any pre-computed
|
|
18
|
-
embeddings exercise the same Atlas $vectorSearch surface, since the
|
|
19
|
-
index contract is (path, dims, similarity) — provider is metadata.
|
|
20
|
-
|
|
21
|
-
Two presets:
|
|
22
|
-
|
|
23
|
-
PRESET=fast (default) — Cohere/wikipedia-22-12-simple-embeddings
|
|
24
|
-
768-dim, ~13MB shards, ~485k rows total. Quick to download.
|
|
25
|
-
Use when iterating on pipeline mechanics, not Voyage-shape parity.
|
|
26
|
-
|
|
27
|
-
PRESET=voyage_compat — Cohere/wikipedia-2023-11-embed-multilingual-v3
|
|
28
|
-
1024-dim (matches voyage-multimodal-3), ~1.5GB shards.
|
|
29
|
-
Use when the index/query surface needs to be Voyage-dimension-shaped
|
|
30
|
-
even though vectors come from Cohere. Vectors are NOT interchangeable
|
|
31
|
-
with Voyage outputs — same dim, different latent space — but the
|
|
32
|
-
SDK pipeline mechanics are validated correctly.
|
|
33
|
-
|
|
34
|
-
For actual Voyage-vector parity at test time, compute query vectors via
|
|
35
|
-
the Voyage API into the same 1024-dim index (no local-inference path
|
|
36
|
-
exists — Voyage models are closed-weights, API-only).
|
|
37
|
-
|
|
38
|
-
Prereqs: pip install pyarrow pymongo requests
|
|
39
|
-
|
|
40
|
-
Run: python3 scripts/vector_prototype/fetch_embeddings.py
|
|
41
|
-
"""
|
|
42
|
-
|
|
43
|
-
import os
|
|
44
|
-
import sys
|
|
45
|
-
import datetime
|
|
46
|
-
import requests
|
|
47
|
-
import pyarrow.parquet as pq
|
|
48
|
-
from pymongo import MongoClient
|
|
49
|
-
|
|
50
|
-
PRESETS = {
|
|
51
|
-
"fast": {
|
|
52
|
-
# MongoDB's reference dataset for Atlas Vector Search demos.
|
|
53
|
-
# ~3500 movies × 1536-dim OpenAI ada-002 plot embeddings.
|
|
54
|
-
# Public, ~42MB, single JSON file. Format: array of objects with
|
|
55
|
-
# plot_embedding field.
|
|
56
|
-
"url": "https://huggingface.co/datasets/MongoDB/embedded_movies/resolve/main/sample_mflix.embedded_movies.json",
|
|
57
|
-
"dims": 1536,
|
|
58
|
-
"provider": "openai-text-embedding-ada-002",
|
|
59
|
-
"format": "json",
|
|
60
|
-
"embedding_field": "plot_embedding",
|
|
61
|
-
"id_field": None, # MongoDB will auto-assign or we synthesize
|
|
62
|
-
},
|
|
63
|
-
"voyage_compat": {
|
|
64
|
-
# 1024-dim matches voyage-multimodal-3 — same index shape, different
|
|
65
|
-
# latent space. Vectors NOT mixable with Voyage outputs at query time.
|
|
66
|
-
# NOTE: requires an authenticated HuggingFace download
|
|
67
|
-
# (HF_TOKEN env var or `huggingface-cli login`). The Cohere wikipedia
|
|
68
|
-
# v3 dataset is gated since late 2024.
|
|
69
|
-
"url": "https://huggingface.co/datasets/Cohere/wikipedia-2023-11-embed-multilingual-v3/resolve/main/en/0000.parquet",
|
|
70
|
-
"dims": 1024,
|
|
71
|
-
"provider": "cohere-embed-multilingual-v3",
|
|
72
|
-
"format": "parquet",
|
|
73
|
-
"embedding_field": "emb",
|
|
74
|
-
"id_field": "id",
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
PRESET = os.environ.get("PRESET", "fast")
|
|
79
|
-
if PRESET not in PRESETS:
|
|
80
|
-
print(f"[err] unknown PRESET={PRESET}; choose one of: {list(PRESETS)}", file=sys.stderr)
|
|
81
|
-
sys.exit(2)
|
|
82
|
-
|
|
83
|
-
_p = PRESETS[PRESET]
|
|
84
|
-
DATASET_URL = os.environ.get("DATASET_URL", _p["url"])
|
|
85
|
-
DIMS_EXPECTED = int(os.environ.get("DIMS_EXPECTED", _p["dims"]))
|
|
86
|
-
PROVIDER_LABEL = os.environ.get("PROVIDER_LABEL", _p["provider"])
|
|
87
|
-
DATA_FORMAT = _p["format"]
|
|
88
|
-
EMBEDDING_FIELD = _p["embedding_field"]
|
|
89
|
-
ID_FIELD = _p["id_field"]
|
|
90
|
-
|
|
91
|
-
_ext = "parquet" if DATA_FORMAT == "parquet" else "json"
|
|
92
|
-
LOCAL_FILE = os.environ.get("LOCAL_FILE", f"/tmp/parse-stack-fixture-{PRESET}.{_ext}")
|
|
93
|
-
MONGO_URI = os.environ.get("ATLAS_URI", "mongodb://localhost:29020/?directConnection=true")
|
|
94
|
-
DB_NAME = os.environ.get("DB_NAME", "vector_prototype")
|
|
95
|
-
# Collection name mirrors the dataset shape so RAG tests can pivot
|
|
96
|
-
# without coupling test assertions to a hard-coded class name.
|
|
97
|
-
DEFAULT_COLL = "Movie" if PRESET == "fast" else "WikiArticle"
|
|
98
|
-
COLL_NAME = os.environ.get("COLL_NAME", DEFAULT_COLL)
|
|
99
|
-
LIMIT = int(os.environ.get("LIMIT", "10000"))
|
|
100
|
-
|
|
101
|
-
print(f"[preset] {PRESET} provider={PROVIDER_LABEL} dims={DIMS_EXPECTED}")
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def download():
|
|
105
|
-
if os.path.exists(LOCAL_FILE) and os.path.getsize(LOCAL_FILE) > 0:
|
|
106
|
-
print(f"[skip] {LOCAL_FILE} already present ({os.path.getsize(LOCAL_FILE)} bytes)")
|
|
107
|
-
return
|
|
108
|
-
headers = {}
|
|
109
|
-
token = os.environ.get("HF_TOKEN")
|
|
110
|
-
if token:
|
|
111
|
-
headers["Authorization"] = f"Bearer {token}"
|
|
112
|
-
print(f"[download] {DATASET_URL}")
|
|
113
|
-
with requests.get(DATASET_URL, stream=True, timeout=120, headers=headers) as r:
|
|
114
|
-
if r.status_code == 401:
|
|
115
|
-
print(
|
|
116
|
-
f"[err] HTTP 401 — dataset requires authentication. "
|
|
117
|
-
f"Set HF_TOKEN env var (huggingface.co token) or pick a different PRESET.",
|
|
118
|
-
file=sys.stderr,
|
|
119
|
-
)
|
|
120
|
-
sys.exit(2)
|
|
121
|
-
r.raise_for_status()
|
|
122
|
-
total = int(r.headers.get("content-length", 0))
|
|
123
|
-
written = 0
|
|
124
|
-
with open(LOCAL_FILE, "wb") as f:
|
|
125
|
-
for chunk in r.iter_content(chunk_size=1024 * 1024):
|
|
126
|
-
f.write(chunk)
|
|
127
|
-
written += len(chunk)
|
|
128
|
-
if total:
|
|
129
|
-
pct = 100 * written / total
|
|
130
|
-
print(f" {written // (1024*1024)}MB / {total // (1024*1024)}MB ({pct:.1f}%)", end="\r")
|
|
131
|
-
print()
|
|
132
|
-
print(f"[download] wrote {LOCAL_FILE}")
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def _read_rows():
|
|
136
|
-
if DATA_FORMAT == "parquet":
|
|
137
|
-
print(f"[read] parquet {LOCAL_FILE}")
|
|
138
|
-
table = pq.read_table(LOCAL_FILE)
|
|
139
|
-
print(f"[read] rows={table.num_rows} columns={table.column_names}")
|
|
140
|
-
return table.to_pylist()
|
|
141
|
-
elif DATA_FORMAT == "json":
|
|
142
|
-
print(f"[read] json {LOCAL_FILE}")
|
|
143
|
-
import json as _json
|
|
144
|
-
with open(LOCAL_FILE, "r") as f:
|
|
145
|
-
data = _json.load(f)
|
|
146
|
-
# embedded_movies is a top-level array
|
|
147
|
-
if not isinstance(data, list):
|
|
148
|
-
print(f"[err] expected top-level JSON array, got {type(data).__name__}", file=sys.stderr)
|
|
149
|
-
sys.exit(1)
|
|
150
|
-
print(f"[read] rows={len(data)}")
|
|
151
|
-
if data:
|
|
152
|
-
print(f"[read] sample keys: {list(data[0].keys())[:10]}")
|
|
153
|
-
return data
|
|
154
|
-
else:
|
|
155
|
-
print(f"[err] unknown DATA_FORMAT={DATA_FORMAT}", file=sys.stderr)
|
|
156
|
-
sys.exit(1)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def load():
|
|
160
|
-
rows = _read_rows()
|
|
161
|
-
if LIMIT > 0:
|
|
162
|
-
rows = rows[:LIMIT]
|
|
163
|
-
if not rows:
|
|
164
|
-
print("[err] no rows", file=sys.stderr)
|
|
165
|
-
sys.exit(1)
|
|
166
|
-
|
|
167
|
-
# Find the first row that actually has an embedding (some datasets,
|
|
168
|
-
# including embedded_movies, have null embeddings for entries with
|
|
169
|
-
# missing plot text).
|
|
170
|
-
sample = next((r for r in rows if r.get(EMBEDDING_FIELD)), None)
|
|
171
|
-
if sample is None:
|
|
172
|
-
print(f"[err] no rows have field '{EMBEDDING_FIELD}'; sample keys: {list(rows[0].keys())}", file=sys.stderr)
|
|
173
|
-
sys.exit(1)
|
|
174
|
-
dims = len(sample[EMBEDDING_FIELD])
|
|
175
|
-
print(f"[verify] embedding field='{EMBEDDING_FIELD}' dims={dims}")
|
|
176
|
-
if dims != DIMS_EXPECTED:
|
|
177
|
-
print(
|
|
178
|
-
f"[warn] dims={dims} differs from preset DIMS_EXPECTED={DIMS_EXPECTED}; "
|
|
179
|
-
f"manifest will record the actual dims",
|
|
180
|
-
file=sys.stderr,
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
now = datetime.datetime.utcnow()
|
|
184
|
-
docs = []
|
|
185
|
-
skipped = 0
|
|
186
|
-
for idx, r in enumerate(rows):
|
|
187
|
-
emb = r.get(EMBEDDING_FIELD)
|
|
188
|
-
if not emb or len(emb) != dims:
|
|
189
|
-
skipped += 1
|
|
190
|
-
continue
|
|
191
|
-
# Carry through dataset fields (text/title/etc.) so RAG/chunker
|
|
192
|
-
# tests have real content. Source fields go first; our canonical
|
|
193
|
-
# fields win.
|
|
194
|
-
doc = {k: v for k, v in r.items() if k != EMBEDDING_FIELD}
|
|
195
|
-
doc["embedding"] = list(emb)
|
|
196
|
-
doc["_created_at"] = now
|
|
197
|
-
doc["_updated_at"] = now
|
|
198
|
-
if ID_FIELD and r.get(ID_FIELD) is not None:
|
|
199
|
-
doc["_id"] = f"{COLL_NAME.lower()}_{r[ID_FIELD]}"
|
|
200
|
-
else:
|
|
201
|
-
doc["_id"] = f"{COLL_NAME.lower()}_{idx:06d}"
|
|
202
|
-
docs.append(doc)
|
|
203
|
-
|
|
204
|
-
if skipped:
|
|
205
|
-
print(f"[load] skipped {skipped} rows missing/short embeddings")
|
|
206
|
-
|
|
207
|
-
client = MongoClient(MONGO_URI)
|
|
208
|
-
coll = client[DB_NAME][COLL_NAME]
|
|
209
|
-
print(f"[mongo] dropping {DB_NAME}.{COLL_NAME}")
|
|
210
|
-
coll.drop()
|
|
211
|
-
|
|
212
|
-
# Bulk insert in chunks — pymongo's default is fine but explicit is clearer
|
|
213
|
-
BATCH = 1000
|
|
214
|
-
for i in range(0, len(docs), BATCH):
|
|
215
|
-
coll.insert_many(docs[i:i + BATCH], ordered=False)
|
|
216
|
-
print(f" inserted {min(i + BATCH, len(docs))}/{len(docs)}")
|
|
217
|
-
|
|
218
|
-
count = coll.count_documents({})
|
|
219
|
-
print(f"[mongo] {DB_NAME}.{COLL_NAME} now has {count} docs (embedding dims={dims})")
|
|
220
|
-
|
|
221
|
-
# Manifest — single source of truth shared with create_vector_index.js
|
|
222
|
-
# so the index name + dimensions can never drift from the loaded data.
|
|
223
|
-
import json
|
|
224
|
-
manifest = {
|
|
225
|
-
"preset": PRESET,
|
|
226
|
-
"provider": PROVIDER_LABEL,
|
|
227
|
-
"dims": dims,
|
|
228
|
-
"db": DB_NAME,
|
|
229
|
-
"collection": COLL_NAME,
|
|
230
|
-
"count": count,
|
|
231
|
-
"index_name": f"{COLL_NAME}_embedding_{PROVIDER_LABEL.replace('-', '_')}_{dims}_idx",
|
|
232
|
-
}
|
|
233
|
-
manifest_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixture_manifest.json")
|
|
234
|
-
with open(manifest_path, "w") as f:
|
|
235
|
-
json.dump(manifest, f, indent=2)
|
|
236
|
-
print(f"[manifest] wrote {manifest_path}: {manifest['index_name']}")
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if __name__ == "__main__":
|
|
240
|
-
download()
|
|
241
|
-
load()
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# Exercise Atlas $vectorSearch end-to-end via the Ruby mongo driver — the
|
|
3
|
-
# same driver Parse::MongoDB.aggregate uses. This is the literal pipeline
|
|
4
|
-
# shape Parse::VectorSearch will produce (vector_rag_plan.md §3).
|
|
5
|
-
#
|
|
6
|
-
# Run:
|
|
7
|
-
# bundle exec ruby scripts/vector_prototype/query_prototype.rb
|
|
8
|
-
#
|
|
9
|
-
# Prereq: fetch_embeddings.py + create_vector_index.js have been run, so
|
|
10
|
-
# vector_prototype.WikiArticle is populated and the search index is
|
|
11
|
-
# queryable.
|
|
12
|
-
#
|
|
13
|
-
# This script intentionally avoids any Parse::* SDK code — it's the raw
|
|
14
|
-
# Atlas surface, used as the ground-truth comparison once Parse::VectorSearch
|
|
15
|
-
# lands. The same pipeline shape will be emitted by Parse::VectorSearch::SearchBuilder.
|
|
16
|
-
|
|
17
|
-
require "mongo"
|
|
18
|
-
|
|
19
|
-
require "json"
|
|
20
|
-
|
|
21
|
-
MANIFEST_PATH = File.expand_path("fixture_manifest.json", __dir__)
|
|
22
|
-
unless File.exist?(MANIFEST_PATH)
|
|
23
|
-
abort "no fixture_manifest.json — run fetch_embeddings.py first"
|
|
24
|
-
end
|
|
25
|
-
MANIFEST = JSON.parse(File.read(MANIFEST_PATH))
|
|
26
|
-
|
|
27
|
-
MONGO_URI = ENV.fetch("ATLAS_URI", "mongodb://localhost:29020/#{MANIFEST['db']}?directConnection=true")
|
|
28
|
-
INDEX_NAME = ENV.fetch("VECTOR_INDEX", MANIFEST["index_name"])
|
|
29
|
-
COLL_NAME = MANIFEST["collection"].to_sym
|
|
30
|
-
|
|
31
|
-
puts "[manifest] preset=#{MANIFEST['preset']} provider=#{MANIFEST['provider']} dims=#{MANIFEST['dims']} index=#{INDEX_NAME}"
|
|
32
|
-
|
|
33
|
-
client = Mongo::Client.new(MONGO_URI)
|
|
34
|
-
coll = client[COLL_NAME]
|
|
35
|
-
|
|
36
|
-
count = coll.count_documents({})
|
|
37
|
-
abort "no docs loaded — run fetch_embeddings.py first" if count.zero?
|
|
38
|
-
puts "[setup] #{count} docs in #{client.database.name}.#{COLL_NAME}"
|
|
39
|
-
|
|
40
|
-
# Use an existing doc's vector as the query — exercises the index without
|
|
41
|
-
# requiring an embedding API. When Voyage lands, swap this for a freshly
|
|
42
|
-
# computed query vector against the same index.
|
|
43
|
-
seed = coll.find.limit(1).first
|
|
44
|
-
puts "[seed] #{seed["title"]} (#{seed["embedding"].size}-dim)"
|
|
45
|
-
|
|
46
|
-
pipeline = [
|
|
47
|
-
{
|
|
48
|
-
"$vectorSearch" => {
|
|
49
|
-
"index" => INDEX_NAME,
|
|
50
|
-
"path" => "embedding",
|
|
51
|
-
"queryVector" => seed["embedding"],
|
|
52
|
-
"numCandidates" => 200,
|
|
53
|
-
"limit" => 10,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"$project" => {
|
|
58
|
-
"_id" => 1,
|
|
59
|
-
"title" => 1,
|
|
60
|
-
# Project the score under _vscore (not _score) so hybrid search with
|
|
61
|
-
# Atlas Search lexical scores doesn't collide. Matches the convention
|
|
62
|
-
# the SDK will adopt — vector_rag_plan.md §3.
|
|
63
|
-
"_vscore" => { "$meta" => "vectorSearchScore" },
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
puts "[query] $vectorSearch limit=10 numCandidates=200"
|
|
69
|
-
t0 = Time.now
|
|
70
|
-
results = coll.aggregate(pipeline).to_a
|
|
71
|
-
elapsed_ms = ((Time.now - t0) * 1000).round(1)
|
|
72
|
-
|
|
73
|
-
puts "[result] #{results.size} hits in #{elapsed_ms}ms"
|
|
74
|
-
results.each_with_index do |r, i|
|
|
75
|
-
printf(" %2d. score=%.4f %s\n", i + 1, r["_vscore"], r["title"])
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# Sanity: top hit should be the seed itself (cosine = 1.0)
|
|
79
|
-
top = results.first
|
|
80
|
-
if top && top["_id"] == seed["_id"]
|
|
81
|
-
puts "[ok] top hit == seed (self-similarity verified)"
|
|
82
|
-
else
|
|
83
|
-
puts "[warn] top hit was not the seed — index may still be building"
|
|
84
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Orchestrate the vector-search / RAG test fixture setup.
|
|
3
|
-
# Assumes the Atlas Local container from docker-compose.atlas.yml is up
|
|
4
|
-
# (i.e. localhost:29020 is reachable).
|
|
5
|
-
#
|
|
6
|
-
# Usage: ./scripts/vector_prototype/run.sh
|
|
7
|
-
#
|
|
8
|
-
# Once this stabilises, the fetch + index-create steps will be folded
|
|
9
|
-
# into scripts/docker/docker-compose.atlas.yml as additional init
|
|
10
|
-
# containers, alongside the existing atlas-init service.
|
|
11
|
-
|
|
12
|
-
set -euo pipefail
|
|
13
|
-
|
|
14
|
-
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
15
|
-
|
|
16
|
-
echo "[1/3] verifying Atlas Local on localhost:29020"
|
|
17
|
-
if ! mongosh --quiet --eval "db.runCommand({ ping: 1 })" \
|
|
18
|
-
"mongodb://localhost:29020/?directConnection=true" >/dev/null; then
|
|
19
|
-
echo " ERROR: Atlas Local not reachable. Start it with:"
|
|
20
|
-
echo " docker-compose -f scripts/docker/docker-compose.atlas.yml up -d"
|
|
21
|
-
exit 1
|
|
22
|
-
fi
|
|
23
|
-
echo " ok"
|
|
24
|
-
|
|
25
|
-
echo "[2/3] downloading + loading embeddings"
|
|
26
|
-
python3 "$HERE/fetch_embeddings.py"
|
|
27
|
-
|
|
28
|
-
echo "[3/3] creating vectorSearch index"
|
|
29
|
-
mongosh --quiet "mongodb://localhost:29020/vector_prototype?directConnection=true" \
|
|
30
|
-
"$HERE/create_vector_index.js"
|
|
31
|
-
|
|
32
|
-
echo
|
|
33
|
-
echo "Done. Run the Ruby query exercise with:"
|
|
34
|
-
echo " bundle exec ruby scripts/vector_prototype/query_prototype.rb"
|