@aryasaatvik/scratchpad 0.6.2 → 0.6.3

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## @aryasaatvik/scratchpad@0.6.3
2
+
3
+ ### Build the search index faster
4
+
5
+ Search now embeds chunks across notes in shared batches and sends up to eight embedding requests at once, instead of one request per changed note. A cold index of about 1,500 notes no longer takes an hour.
6
+
1
7
  ## @aryasaatvik/scratchpad@0.6.2
2
8
 
3
9
  ### Treat `codemaps/` as part of the default notes layout
@@ -51974,7 +51974,7 @@ var bundleHtml = async (options) => {
51974
51974
  // package.json
51975
51975
  var package_default = {
51976
51976
  name: "@aryasaatvik/scratchpad",
51977
- version: "0.6.2",
51977
+ version: "0.6.3",
51978
51978
  description: "Working memory for coding agents: project notes shared across worktrees, instruction feedback, note search and lifecycle cleanup, plus GitHub backlog sync, hosted artifacts and codemaps.",
51979
51979
  keywords: [
51980
51980
  "bun",
@@ -55458,6 +55458,26 @@ var searchError = (cause) => cause instanceof SearchError || cause instanceof Se
55458
55458
  // packages/cli/src/search/embeddings.ts
55459
55459
  var DIMENSIONS = 1024;
55460
55460
  var MODEL = "qwen/qwen3-embedding-8b";
55461
+ var EMBED_REQUEST_SIZE = 64;
55462
+ var EMBED_CONCURRENCY = 8;
55463
+ var mapConcurrent = async (items, limit, f) => {
55464
+ const results = new Array(items.length);
55465
+ let next = 0;
55466
+ let failed = false;
55467
+ const worker = async () => {
55468
+ while (!failed && next < items.length) {
55469
+ const i = next++;
55470
+ try {
55471
+ results[i] = await f(items[i]);
55472
+ } catch (cause) {
55473
+ failed = true;
55474
+ throw cause;
55475
+ }
55476
+ }
55477
+ };
55478
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
55479
+ return results;
55480
+ };
55461
55481
  var Response2 = Struct({
55462
55482
  data: ArraySchema(Struct({
55463
55483
  index: Number6,
@@ -55467,9 +55487,10 @@ var Response2 = Struct({
55467
55487
  var openRouter = (key) => ({
55468
55488
  identity: `${MODEL}:${DIMENSIONS}:v1`,
55469
55489
  async embed(texts) {
55470
- const vectors = [];
55471
- for (let offset = 0;offset < texts.length; offset += 64) {
55472
- const input = texts.slice(offset, offset + 64);
55490
+ const batches = [];
55491
+ for (let offset = 0;offset < texts.length; offset += EMBED_REQUEST_SIZE)
55492
+ batches.push(texts.slice(offset, offset + EMBED_REQUEST_SIZE));
55493
+ const results = await mapConcurrent(batches, EMBED_CONCURRENCY, async (input) => {
55473
55494
  const response = await fetch("https://openrouter.ai/api/v1/embeddings", {
55474
55495
  method: "POST",
55475
55496
  signal: AbortSignal.timeout(60000),
@@ -55487,9 +55508,9 @@ var openRouter = (key) => ({
55487
55508
  throw new SearchError({
55488
55509
  message: "Embedding response has invalid indexes, count or dimensions"
55489
55510
  });
55490
- vectors.push(...data.map((d) => [...d.embedding]));
55491
- }
55492
- return vectors;
55511
+ return data.map((d) => [...d.embedding]);
55512
+ });
55513
+ return results.flat();
55493
55514
  }
55494
55515
  });
55495
55516
  var embed = (embedder, texts) => tryPromise2({ try: () => embedder.embed(texts), catch: searchError });
@@ -55729,6 +55750,24 @@ var inBatches = (items, write) => {
55729
55750
  results.push(...write(items.slice(i, i + VECTOR_WRITE_BATCH)));
55730
55751
  return results;
55731
55752
  };
55753
+ var EMBED_GROUP_CHUNKS = 512;
55754
+ var groupByChunks = (notes, size) => {
55755
+ const groups = [];
55756
+ let group = [];
55757
+ let count = 0;
55758
+ for (const note of notes) {
55759
+ group.push(note);
55760
+ count += note.pending.length;
55761
+ if (count >= size) {
55762
+ groups.push(group);
55763
+ group = [];
55764
+ count = 0;
55765
+ }
55766
+ }
55767
+ if (group.length)
55768
+ groups.push(group);
55769
+ return groups;
55770
+ };
55732
55771
  var Metadata = Struct({
55733
55772
  title: optional2(String5),
55734
55773
  kind: optional2(String5)
@@ -55819,9 +55858,10 @@ var run6 = fn2("Search.run")(function* (options, query) {
55819
55858
  const vectorWriter = options.embedder ? yield* acquireRelease2(tryPromise2({ try: () => writer(vectorPath), catch: searchError }), (c) => sync2(() => c.closeSync())) : undefined;
55820
55859
  const vectorEmpty = vectorWriter?.stats.docCount === 0;
55821
55860
  let changed = 0;
55861
+ const embeddingIdentity = options.embedder?.identity;
55862
+ const prepared = [];
55822
55863
  for (const [path, text] of sources) {
55823
55864
  const fileHash = hash3(text);
55824
- const embeddingIdentity = options.embedder?.identity;
55825
55865
  const needsVectors = embeddingIdentity !== undefined && (vectorEmpty || (oldByPath.get(path) ?? []).some((c) => c.notePath === path && c.vectorHash !== hash3(`${embeddingIdentity}:${c.contentHash}`)));
55826
55866
  if (!options.rebuild && files.get(path) === fileHash && !needsVectors)
55827
55867
  continue;
@@ -55836,8 +55876,12 @@ var run6 = fn2("Search.run")(function* (options, query) {
55836
55876
  vectorHash: oldChunks.get(c.id)?.contentHash === c.contentHash ? oldChunks.get(c.id)?.vectorHash ?? null : null
55837
55877
  }));
55838
55878
  const pending = chunks.filter((c) => options.rebuild || vectorEmpty || oldChunks.get(c.id)?.vectorHash !== hash3(`${embeddingIdentity}:${c.contentHash}`));
55839
- if (options.embedder && vectorWriter) {
55840
- const vectors = yield* embed(options.embedder, pending.map(embeddingInput));
55879
+ prepared.push({ path, fileHash, chunks, pending });
55880
+ }
55881
+ for (const group of groupByChunks(prepared, EMBED_GROUP_CHUNKS)) {
55882
+ const pending = group.flatMap((note) => note.pending);
55883
+ if (options.embedder && vectorWriter && embeddingIdentity !== undefined) {
55884
+ const vectors = pending.length ? yield* embed(options.embedder, pending.map(embeddingInput)) : [];
55841
55885
  yield* try_3({
55842
55886
  try: () => {
55843
55887
  const docs = pending.map((c, i) => {
@@ -55853,17 +55897,19 @@ var run6 = fn2("Search.run")(function* (options, query) {
55853
55897
  if (failed)
55854
55898
  throw new SearchError({ message: `Vector upsert failed: ${failed.message}` });
55855
55899
  }
55856
- for (const c of chunks)
55857
- c.vectorHash = hash3(`${embeddingIdentity}:${c.contentHash}`);
55900
+ for (const note of group)
55901
+ for (const c of note.chunks)
55902
+ c.vectorHash = hash3(`${embeddingIdentity}:${c.contentHash}`);
55858
55903
  },
55859
55904
  catch: searchError
55860
55905
  });
55861
55906
  }
55862
- yield* try_3({
55863
- try: () => store.replace(path, fileHash, chunks),
55864
- catch: searchError
55865
- });
55866
- changed++;
55907
+ for (const note of group)
55908
+ yield* try_3({
55909
+ try: () => store.replace(note.path, note.fileHash, note.chunks),
55910
+ catch: searchError
55911
+ });
55912
+ changed += group.length;
55867
55913
  }
55868
55914
  const deleted = [...files.keys()].filter((path) => !sources.has(path));
55869
55915
  yield* try_3({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aryasaatvik/scratchpad",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Working memory for coding agents: project notes shared across worktrees, instruction feedback, note search and lifecycle cleanup, plus GitHub backlog sync, hosted artifacts and codemaps.",
5
5
  "keywords": [
6
6
  "bun",