@promptev/context-engine 0.0.0 → 0.0.2

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.
Files changed (60) hide show
  1. package/README.md +116 -5
  2. package/dist/cli.js +1896 -552
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{config-Bl9U789m.d.cts → config-BODDdXJ7.d.ts} +75 -16
  5. package/dist/{config-Bt9bUQqU.d.ts → config-C5RZ00W6.d.cts} +75 -16
  6. package/dist/express.cjs +925 -151
  7. package/dist/express.cjs.map +1 -1
  8. package/dist/express.d.cts +11 -4
  9. package/dist/express.d.ts +11 -4
  10. package/dist/express.js +926 -152
  11. package/dist/express.js.map +1 -1
  12. package/dist/fastify.cjs +923 -151
  13. package/dist/fastify.cjs.map +1 -1
  14. package/dist/fastify.d.cts +8 -4
  15. package/dist/fastify.d.ts +8 -4
  16. package/dist/fastify.js +924 -152
  17. package/dist/fastify.js.map +1 -1
  18. package/dist/{governance-XIScatRO.d.ts → governance-BLPK7NMe.d.ts} +8 -2
  19. package/dist/{governance-BDkcv4qZ.d.cts → governance-P9pRb4Ol.d.cts} +8 -2
  20. package/dist/graph/index.cjs +171 -59
  21. package/dist/graph/index.cjs.map +1 -1
  22. package/dist/graph/index.d.cts +5 -3
  23. package/dist/graph/index.d.ts +5 -3
  24. package/dist/graph/index.js +171 -59
  25. package/dist/graph/index.js.map +1 -1
  26. package/dist/hono.cjs +923 -151
  27. package/dist/hono.cjs.map +1 -1
  28. package/dist/hono.d.cts +8 -4
  29. package/dist/hono.d.ts +8 -4
  30. package/dist/hono.js +924 -152
  31. package/dist/hono.js.map +1 -1
  32. package/dist/index.cjs +2413 -1052
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +125 -107
  35. package/dist/index.d.ts +125 -107
  36. package/dist/index.js +2412 -1050
  37. package/dist/index.js.map +1 -1
  38. package/dist/mcp.cjs +100 -14
  39. package/dist/mcp.cjs.map +1 -1
  40. package/dist/mcp.d.cts +5 -0
  41. package/dist/mcp.d.ts +5 -0
  42. package/dist/mcp.js +100 -14
  43. package/dist/mcp.js.map +1 -1
  44. package/dist/migrations/sql/0003_tools.sql +2 -0
  45. package/dist/migrations/sql/0004_acl_indexes.sql +23 -2
  46. package/dist/{redaction-BmDSWJ7h.d.cts → redaction-BqD_DEUQ.d.cts} +22 -1
  47. package/dist/{redaction-BmDSWJ7h.d.ts → redaction-BqD_DEUQ.d.ts} +22 -1
  48. package/dist/redaction-presidio.d.cts +1 -1
  49. package/dist/redaction-presidio.d.ts +1 -1
  50. package/dist/{router-CrxZ2y_Z.d.ts → router-CiFwC-EN.d.cts} +17 -2
  51. package/dist/{router-OPgSoYAB.d.cts → router-D8gBzwLd.d.ts} +17 -2
  52. package/dist/skills/context-engine/SKILL.md +5 -1
  53. package/dist/storage-CJrKgJeJ.d.ts +167 -0
  54. package/dist/storage-Dvpq2xAC.d.cts +167 -0
  55. package/package.json +61 -23
  56. package/src/migrations/sql/0003_tools.sql +2 -0
  57. package/src/migrations/sql/0004_acl_indexes.sql +23 -2
  58. package/src/skills/context-engine/SKILL.md +5 -1
  59. package/dist/embeddings-B-jZ42mk.d.cts +0 -67
  60. package/dist/embeddings-DaSdAZN3.d.ts +0 -67
@@ -1,7 +1,7 @@
1
1
  import { Pool } from 'pg';
2
- import { G as GraphConfig, C as ContextEngineConfig } from '../config-Bl9U789m.cjs';
3
- import { H as Hooks } from '../redaction-BmDSWJ7h.cjs';
4
- import { E as Embedder } from '../embeddings-B-jZ42mk.cjs';
2
+ import { G as GraphConfig, C as ContextEngineConfig } from '../config-C5RZ00W6.cjs';
3
+ import { H as Hooks } from '../redaction-BqD_DEUQ.cjs';
4
+ import { E as Embedder, A as AnnTunable } from '../storage-Dvpq2xAC.cjs';
5
5
  import 'zod';
6
6
 
7
7
  type Neo4jDriver = {
@@ -63,8 +63,10 @@ declare function buildGraphRanked$1(query: string, opts: {
63
63
  graphStore: GraphStore;
64
64
  hooks?: Hooks | null;
65
65
  sourceIds?: string[] | null;
66
+ documentIds?: string[] | null;
66
67
  principals?: string[] | null;
67
68
  maxDepth?: number;
69
+ backend?: Partial<AnnTunable> | null;
68
70
  }): Promise<string[]>;
69
71
 
70
72
  declare function runGraphStage$1(opts: {
@@ -1,7 +1,7 @@
1
1
  import { Pool } from 'pg';
2
- import { G as GraphConfig, C as ContextEngineConfig } from '../config-Bt9bUQqU.js';
3
- import { H as Hooks } from '../redaction-BmDSWJ7h.js';
4
- import { E as Embedder } from '../embeddings-DaSdAZN3.js';
2
+ import { G as GraphConfig, C as ContextEngineConfig } from '../config-BODDdXJ7.js';
3
+ import { H as Hooks } from '../redaction-BqD_DEUQ.js';
4
+ import { E as Embedder, A as AnnTunable } from '../storage-CJrKgJeJ.js';
5
5
  import 'zod';
6
6
 
7
7
  type Neo4jDriver = {
@@ -63,8 +63,10 @@ declare function buildGraphRanked$1(query: string, opts: {
63
63
  graphStore: GraphStore;
64
64
  hooks?: Hooks | null;
65
65
  sourceIds?: string[] | null;
66
+ documentIds?: string[] | null;
66
67
  principals?: string[] | null;
67
68
  maxDepth?: number;
69
+ backend?: Partial<AnnTunable> | null;
68
70
  }): Promise<string[]>;
69
71
 
70
72
  declare function runGraphStage$1(opts: {
@@ -59,9 +59,52 @@ var init_hooks = __esm({
59
59
  }
60
60
  });
61
61
 
62
+ // src/providers/google.ts
63
+ async function buildGenaiClient(cfg, timeoutMs, purpose) {
64
+ const specifier = "@google/genai";
65
+ let mod;
66
+ try {
67
+ mod = await import(specifier);
68
+ } catch {
69
+ throw new ExtraMissingError("gemini", specifier, purpose);
70
+ }
71
+ const Ctor = mod.GoogleGenAI ?? mod.Client;
72
+ if (!Ctor) {
73
+ throw new ExtraMissingError("gemini", specifier, purpose);
74
+ }
75
+ const opts = { httpOptions: { timeout: timeoutMs } };
76
+ if (cfg.provider === "vertex_ai") {
77
+ opts.vertexai = true;
78
+ if (cfg.project || cfg.location) {
79
+ if (cfg.project) opts.project = cfg.project;
80
+ if (cfg.location) opts.location = cfg.location;
81
+ } else if (cfg.apiKey) {
82
+ opts.apiKey = cfg.apiKey;
83
+ }
84
+ } else {
85
+ opts.apiKey = cfg.apiKey ?? null;
86
+ }
87
+ try {
88
+ return new Ctor(opts);
89
+ } catch (err) {
90
+ const message = err instanceof Error ? err.message : String(err);
91
+ if (!message.includes("Authentication is not set up")) throw err;
92
+ throw new Error(
93
+ `${message} Set \`project\` on the provider config, or export GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION. Credentials themselves come from Application Default Credentials.`
94
+ );
95
+ }
96
+ }
97
+ var init_google = __esm({
98
+ "src/providers/google.ts"() {
99
+ init_errors();
100
+ }
101
+ });
102
+
62
103
  // src/providers/llm.ts
63
104
  var llm_exports = {};
64
105
  __export(llm_exports, {
106
+ CALL_TIMEOUT_MS: () => CALL_TIMEOUT_MS,
107
+ GEMINI_CALL_TIMEOUT_MS: () => GEMINI_CALL_TIMEOUT_MS,
65
108
  LLMClient: () => LLMClient,
66
109
  TIMEOUT_MS: () => TIMEOUT_MS,
67
110
  buildLlmClient: () => buildLlmClient,
@@ -92,20 +135,6 @@ function buildOpenAIChatClient(cfg) {
92
135
  maxRetries: 0
93
136
  });
94
137
  }
95
- async function loadGeminiChatClient(apiKey) {
96
- const specifier = "@google/genai";
97
- let mod;
98
- try {
99
- mod = await import(specifier);
100
- } catch {
101
- throw new ExtraMissingError("gemini", specifier, "gemini llm");
102
- }
103
- const Ctor = mod.GoogleGenAI ?? mod.Client;
104
- if (!Ctor) {
105
- throw new ExtraMissingError("gemini", specifier, "gemini llm");
106
- }
107
- return new Ctor({ apiKey: apiKey ?? null });
108
- }
109
138
  async function loadBedrockSdk() {
110
139
  const specifier = "@aws-sdk/client-bedrock-runtime";
111
140
  try {
@@ -124,7 +153,7 @@ function buildLlmClient(cfg, opts) {
124
153
  if (OPENAI_FAMILY.has(cfg.provider)) {
125
154
  return new LLMClient(cfg, { client: buildOpenAIChatClient(cfg) });
126
155
  }
127
- if (cfg.provider === "gemini" || cfg.provider === "bedrock") {
156
+ if (GOOGLE_FAMILY.has(cfg.provider) || cfg.provider === "bedrock") {
128
157
  return new LLMClient(cfg);
129
158
  }
130
159
  throw new Error(`unknown llm provider: ${JSON.stringify(cfg.provider)}`);
@@ -141,14 +170,18 @@ async function callLlm(cfg, opts) {
141
170
  await owned.aclose();
142
171
  }
143
172
  }
144
- var TIMEOUT_MS, ANTHROPIC_VERSION, ANTHROPIC_MAX_TOKENS, OPENAI_FAMILY, LLMClient;
173
+ var CALL_TIMEOUT_MS, TIMEOUT_MS, GEMINI_CALL_TIMEOUT_MS, ANTHROPIC_VERSION, ANTHROPIC_MAX_TOKENS, OPENAI_FAMILY, GOOGLE_FAMILY, LLMClient;
145
174
  var init_llm = __esm({
146
175
  "src/providers/llm.ts"() {
147
176
  init_errors();
148
- TIMEOUT_MS = 3e4;
177
+ init_google();
178
+ CALL_TIMEOUT_MS = 24e4;
179
+ TIMEOUT_MS = CALL_TIMEOUT_MS;
180
+ GEMINI_CALL_TIMEOUT_MS = CALL_TIMEOUT_MS;
149
181
  ANTHROPIC_VERSION = "2023-06-01";
150
182
  ANTHROPIC_MAX_TOKENS = 4096;
151
183
  OPENAI_FAMILY = /* @__PURE__ */ new Set(["openai", "azure_openai", "custom"]);
184
+ GOOGLE_FAMILY = /* @__PURE__ */ new Set(["gemini", "vertex_ai"]);
152
185
  LLMClient = class {
153
186
  cfg;
154
187
  provider;
@@ -173,22 +206,30 @@ var init_llm = __esm({
173
206
  await this.aclose();
174
207
  }
175
208
  async call(opts) {
176
- const { system, user, jsonMode = false, images = null } = opts;
209
+ const {
210
+ system,
211
+ user,
212
+ jsonMode = false,
213
+ images = null,
214
+ maxTokens = null,
215
+ thinkingBudget = null,
216
+ temperature = null
217
+ } = opts;
177
218
  if (this.provider === "anthropic") {
178
- return this.callAnthropic(system, user, jsonMode, images);
219
+ return this.callAnthropic(system, user, jsonMode, images, maxTokens, thinkingBudget, temperature);
179
220
  }
180
221
  if (OPENAI_FAMILY.has(this.provider)) {
181
- return this.callOpenAI(system, user, jsonMode, images);
222
+ return this.callOpenAI(system, user, jsonMode, images, maxTokens, temperature);
182
223
  }
183
- if (this.provider === "gemini") {
184
- return this.callGemini(system, user, jsonMode, images);
224
+ if (GOOGLE_FAMILY.has(this.provider)) {
225
+ return this.callGemini(system, user, jsonMode, images, maxTokens, thinkingBudget, temperature);
185
226
  }
186
227
  if (this.provider === "bedrock") {
187
- return this.callBedrock(system, user, jsonMode, images);
228
+ return this.callBedrock(system, user, jsonMode, images, maxTokens, thinkingBudget, temperature);
188
229
  }
189
230
  throw new Error(`unknown llm provider: ${JSON.stringify(this.provider)}`);
190
231
  }
191
- async callAnthropic(system, user, jsonMode, images) {
232
+ async callAnthropic(system, user, jsonMode, images, maxTokens, thinkingBudget = null, temperature = null) {
192
233
  if (!this.fetchImpl) {
193
234
  throw new Error("anthropic llm client has no fetch implementation");
194
235
  }
@@ -209,26 +250,27 @@ Respond with valid JSON only.`;
209
250
  });
210
251
  }
211
252
  content.push({ type: "text", text: user });
212
- const data = await postJson(
213
- this.fetchImpl,
214
- "https://api.anthropic.com/v1/messages",
215
- {
216
- model: this.model,
217
- max_tokens: ANTHROPIC_MAX_TOKENS,
218
- system,
219
- messages: [{ role: "user", content }]
220
- },
221
- {
222
- "x-api-key": this.cfg.apiKey ?? "",
223
- "anthropic-version": ANTHROPIC_VERSION,
224
- "content-type": "application/json"
225
- }
226
- );
253
+ const body = {
254
+ model: this.model,
255
+ max_tokens: maxTokens ?? ANTHROPIC_MAX_TOKENS,
256
+ system,
257
+ messages: [{ role: "user", content }]
258
+ };
259
+ if (thinkingBudget) {
260
+ body.thinking = { type: "enabled", budget_tokens: thinkingBudget };
261
+ } else if (temperature !== null) {
262
+ body.temperature = temperature;
263
+ }
264
+ const data = await postJson(this.fetchImpl, "https://api.anthropic.com/v1/messages", body, {
265
+ "x-api-key": this.cfg.apiKey ?? "",
266
+ "anthropic-version": ANTHROPIC_VERSION,
267
+ "content-type": "application/json"
268
+ });
227
269
  const text = data.content[0].text;
228
270
  const usage = data.usage ?? {};
229
271
  return [text, { input: usage.input_tokens ?? 0, output: usage.output_tokens ?? 0 }];
230
272
  }
231
- async callOpenAI(system, user, jsonMode, images) {
273
+ async callOpenAI(system, user, jsonMode, images, maxTokens, temperature = null) {
232
274
  if (!this.client) {
233
275
  throw new Error("openai-family llm client has no client");
234
276
  }
@@ -249,24 +291,54 @@ Respond with valid JSON only.`;
249
291
  if (jsonMode) {
250
292
  body.response_format = { type: "json_object" };
251
293
  }
294
+ if (maxTokens) {
295
+ body.max_completion_tokens = maxTokens;
296
+ }
297
+ if (temperature !== null) {
298
+ body.temperature = temperature;
299
+ }
252
300
  const resp = await this.client.chat.completions.create(body);
253
301
  const text = resp.choices[0]?.message?.content ?? "";
254
302
  const usage = resp.usage;
255
303
  return [text, { input: usage?.prompt_tokens ?? 0, output: usage?.completion_tokens ?? 0 }];
256
304
  }
257
- async callGemini(system, user, jsonMode, images) {
305
+ async callGemini(system, user, jsonMode, images, maxTokens, thinkingBudget = null, temperature = null) {
258
306
  if (!this.genaiClient) {
259
- this.genaiClient = await loadGeminiChatClient(this.cfg.apiKey);
307
+ this.genaiClient = await buildGenaiClient(
308
+ this.cfg,
309
+ GEMINI_CALL_TIMEOUT_MS,
310
+ "gemini llm"
311
+ );
260
312
  }
261
313
  const parts = [];
262
314
  for (const img of images ?? []) {
263
315
  parts.push({ inlineData: { mimeType: "image/png", data: toBase64(img) } });
264
316
  }
265
317
  parts.push({ text: user });
266
- const config = { systemInstruction: system };
318
+ const config = {
319
+ systemInstruction: system,
320
+ // ALWAYS off, and not as a preference. Automatic function calling means
321
+ // the SDK itself EXECUTES a callable it was handed as a tool and loops
322
+ // on the result — up to ten round trips — before returning anything.
323
+ // This package passes declarations only, so today nothing is executable;
324
+ // but that depends on every future caller continuing to do the same, and
325
+ // an application that gates tool execution behind human approval would
326
+ // have that gate bypassed silently, by a library, with the loop already
327
+ // run before it could object.
328
+ automaticFunctionCalling: { disable: true }
329
+ };
267
330
  if (jsonMode) {
268
331
  config.responseMimeType = "application/json";
269
332
  }
333
+ if (maxTokens) {
334
+ config.maxOutputTokens = maxTokens;
335
+ }
336
+ if (temperature !== null) {
337
+ config.temperature = temperature;
338
+ }
339
+ if (thinkingBudget !== null) {
340
+ config.thinkingConfig = { thinkingBudget };
341
+ }
270
342
  const resp = await this.genaiClient.models.generateContent({
271
343
  model: this.model,
272
344
  contents: parts,
@@ -278,7 +350,7 @@ Respond with valid JSON only.`;
278
350
  const outputTokens = usageMeta?.candidatesTokenCount ?? usageMeta?.candidates_token_count ?? 0;
279
351
  return [text, { input: inputTokens || 0, output: outputTokens || 0 }];
280
352
  }
281
- async callBedrock(system, user, jsonMode, images) {
353
+ async callBedrock(system, user, jsonMode, images, maxTokens, thinkingBudget = null, temperature = null) {
282
354
  const { BedrockRuntimeClient, ConverseCommand } = await loadBedrockSdk();
283
355
  if (jsonMode) {
284
356
  system = `${system}
@@ -302,7 +374,21 @@ Respond with valid JSON only.`;
302
374
  new ConverseCommand({
303
375
  modelId: this.model,
304
376
  system: [{ text: system }],
305
- messages: [{ role: "user", content }]
377
+ messages: [{ role: "user", content }],
378
+ ...maxTokens || temperature !== null ? {
379
+ inferenceConfig: {
380
+ ...maxTokens ? { maxTokens } : {},
381
+ ...temperature !== null ? { temperature } : {}
382
+ }
383
+ } : {},
384
+ // Anthropic-style passthrough — Converse forwards it to the model.
385
+ // Zero (the vision transcription contract) sends nothing: thinking
386
+ // is opt-in for the anthropic models bedrock hosts.
387
+ ...thinkingBudget ? {
388
+ additionalModelRequestFields: {
389
+ thinking: { type: "enabled", budget_tokens: thinkingBudget }
390
+ }
391
+ } : {}
306
392
  })
307
393
  );
308
394
  const text = result.output?.message?.content?.[0]?.text ?? "";
@@ -1144,7 +1230,8 @@ var retrieval_exports = {};
1144
1230
  __export(retrieval_exports, {
1145
1231
  buildGraphRanked: () => buildGraphRanked,
1146
1232
  corpusIsAclUniform: () => corpusIsAclUniform,
1147
- shouldUseCommunitySummaries: () => shouldUseCommunitySummaries
1233
+ shouldUseCommunitySummaries: () => shouldUseCommunitySummaries,
1234
+ vectorSeedIds: () => vectorSeedIds
1148
1235
  });
1149
1236
  function vecLiteral(vector) {
1150
1237
  return `[${vector.map((x) => Number(x)).join(",")}]`;
@@ -1170,8 +1257,8 @@ async function deriveQueryEntities(pool, chunkIds, opts) {
1170
1257
  JOIN context_engine_chunks c ON c.id = ce.chunk_id
1171
1258
  WHERE ce.chunk_id = ANY($1::uuid[]) ${SCOPE}
1172
1259
  GROUP BY e.normalized_name, e.name, e.type
1173
- ORDER BY freq DESC LIMIT $4`,
1174
- [chunkIds, opts.sourceIds, opts.principals, ENTITY_LIMIT]
1260
+ ORDER BY freq DESC LIMIT $5`,
1261
+ [chunkIds, opts.sourceIds, opts.documentIds ?? null, opts.principals, ENTITY_LIMIT]
1175
1262
  );
1176
1263
  return result.rows.map((r) => ({
1177
1264
  normalized_name: r.normalized_name,
@@ -1236,8 +1323,8 @@ async function computeCommunityScores(pool, chunkIds, vector, opts) {
1236
1323
  `SELECT ce.chunk_id::text, ce.entity_id::text
1237
1324
  FROM context_engine_chunk_entities ce
1238
1325
  JOIN context_engine_chunks c ON c.id = ce.chunk_id
1239
- WHERE ce.chunk_id = ANY($1::uuid[]) AND ce.entity_id = ANY($4::uuid[]) ${SCOPE}`,
1240
- [chunkIds, opts.sourceIds, opts.principals, Object.keys(entityScore)]
1326
+ WHERE ce.chunk_id = ANY($1::uuid[]) AND ce.entity_id = ANY($5::uuid[]) ${SCOPE}`,
1327
+ [chunkIds, opts.sourceIds, opts.documentIds ?? null, opts.principals, Object.keys(entityScore)]
1241
1328
  );
1242
1329
  const chunkScores = {};
1243
1330
  for (const row of result.rows) {
@@ -1246,13 +1333,29 @@ async function computeCommunityScores(pool, chunkIds, vector, opts) {
1246
1333
  return chunkScores;
1247
1334
  }
1248
1335
  async function vectorSeedIds(pool, vector, opts) {
1249
- const result = await pool.query(
1250
- `SELECT c.id::text FROM context_engine_chunks c
1251
- WHERE c.embedding IS NOT NULL ${SCOPE}
1252
- ORDER BY c.embedding <=> CAST($1 AS vector) LIMIT $4`,
1253
- [vecLiteral(vector), opts.sourceIds, opts.principals, SEED_LIMIT]
1254
- );
1255
- return result.rows.map((r) => String(r.id));
1336
+ const binds = [opts.sourceIds, opts.documentIds ?? null, opts.principals];
1337
+ const scoped = binds.some((v) => v !== null);
1338
+ const client = await pool.connect();
1339
+ try {
1340
+ await client.query("BEGIN");
1341
+ await opts.backend?.tuneAnnScan?.(client, SEED_LIMIT, scoped);
1342
+ const result = await client.query(
1343
+ `SELECT c.id::text FROM context_engine_chunks c
1344
+ WHERE c.embedding IS NOT NULL ${SCOPE}
1345
+ ORDER BY c.embedding <=> CAST($1 AS vector) LIMIT $5`,
1346
+ [vecLiteral(vector), ...binds, SEED_LIMIT]
1347
+ );
1348
+ await client.query("COMMIT");
1349
+ return result.rows.map((r) => String(r.id));
1350
+ } catch (err) {
1351
+ try {
1352
+ await client.query("ROLLBACK");
1353
+ } catch {
1354
+ }
1355
+ throw err;
1356
+ } finally {
1357
+ client.release();
1358
+ }
1256
1359
  }
1257
1360
  async function buildGraphRanked(query, opts) {
1258
1361
  try {
@@ -1261,11 +1364,18 @@ async function buildGraphRanked(query, opts) {
1261
1364
  const vector = vectors[0] ? [...vectors[0]] : null;
1262
1365
  if (!vector) return [];
1263
1366
  const sourceIds = opts.sourceIds ?? null;
1367
+ const documentIds = opts.documentIds ?? null;
1264
1368
  const principals = opts.principals ?? null;
1265
- const seeds = await vectorSeedIds(opts.pool, vector, { sourceIds, principals });
1369
+ const seeds = await vectorSeedIds(opts.pool, vector, {
1370
+ sourceIds,
1371
+ documentIds,
1372
+ principals,
1373
+ backend: opts.backend
1374
+ });
1266
1375
  if (!seeds.length) return [];
1267
1376
  const queryEntities = await deriveQueryEntities(opts.pool, seeds.slice(0, TOP_SEEDS_FOR_ENTITIES), {
1268
1377
  sourceIds,
1378
+ documentIds,
1269
1379
  principals
1270
1380
  });
1271
1381
  const entityNorms = queryEntities.map((e) => String(e.normalized_name));
@@ -1287,6 +1397,7 @@ async function buildGraphRanked(query, opts) {
1287
1397
  const relScores = await computeRelationshipScores(opts.pool, allIds, entityNorms);
1288
1398
  const commScores = await computeCommunityScores(opts.pool, allIds, vector, {
1289
1399
  sourceIds,
1400
+ documentIds,
1290
1401
  principals,
1291
1402
  useSummaries
1292
1403
  });
@@ -1338,7 +1449,8 @@ var init_retrieval = __esm({
1338
1449
  TOP_SEEDS_FOR_ENTITIES = 20;
1339
1450
  SCOPE = `
1340
1451
  AND ($2::text[] IS NULL OR c.source_id = ANY($2::text[]))
1341
- AND ($3::text[] IS NULL OR c.acl IS NULL OR c.acl && $3::text[])
1452
+ AND ($3::uuid[] IS NULL OR c.document_id = ANY($3::uuid[]))
1453
+ AND ($4::text[] IS NULL OR c.acl IS NULL OR c.acl && $4::text[])
1342
1454
  `;
1343
1455
  }
1344
1456
  });