@grackle-ai/knowledge-core 0.63.0

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 (65) hide show
  1. package/dist/chunker.d.ts +20 -0
  2. package/dist/chunker.d.ts.map +1 -0
  3. package/dist/chunker.js +7 -0
  4. package/dist/chunker.js.map +1 -0
  5. package/dist/client.d.ts +68 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +150 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/constants.d.ts +33 -0
  10. package/dist/constants.d.ts.map +1 -0
  11. package/dist/constants.js +33 -0
  12. package/dist/constants.js.map +1 -0
  13. package/dist/edge-store.d.ts +32 -0
  14. package/dist/edge-store.d.ts.map +1 -0
  15. package/dist/edge-store.js +145 -0
  16. package/dist/edge-store.js.map +1 -0
  17. package/dist/embedder.d.ts +35 -0
  18. package/dist/embedder.d.ts.map +1 -0
  19. package/dist/embedder.js +7 -0
  20. package/dist/embedder.js.map +1 -0
  21. package/dist/expand.d.ts +42 -0
  22. package/dist/expand.d.ts.map +1 -0
  23. package/dist/expand.js +150 -0
  24. package/dist/expand.js.map +1 -0
  25. package/dist/index.d.ts +31 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +23 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/ingest.d.ts +23 -0
  30. package/dist/ingest.d.ts.map +1 -0
  31. package/dist/ingest.js +27 -0
  32. package/dist/ingest.js.map +1 -0
  33. package/dist/local-embedder.d.ts +25 -0
  34. package/dist/local-embedder.d.ts.map +1 -0
  35. package/dist/local-embedder.js +88 -0
  36. package/dist/local-embedder.js.map +1 -0
  37. package/dist/logger.d.ts +9 -0
  38. package/dist/logger.d.ts.map +1 -0
  39. package/dist/logger.js +15 -0
  40. package/dist/logger.js.map +1 -0
  41. package/dist/node-store.d.ts +116 -0
  42. package/dist/node-store.d.ts.map +1 -0
  43. package/dist/node-store.js +268 -0
  44. package/dist/node-store.js.map +1 -0
  45. package/dist/pass-through-chunker.d.ts +16 -0
  46. package/dist/pass-through-chunker.d.ts.map +1 -0
  47. package/dist/pass-through-chunker.js +21 -0
  48. package/dist/pass-through-chunker.js.map +1 -0
  49. package/dist/schema.d.ts +23 -0
  50. package/dist/schema.d.ts.map +1 -0
  51. package/dist/schema.js +73 -0
  52. package/dist/schema.js.map +1 -0
  53. package/dist/search.d.ts +43 -0
  54. package/dist/search.d.ts.map +1 -0
  55. package/dist/search.js +123 -0
  56. package/dist/search.js.map +1 -0
  57. package/dist/transcript-chunker.d.ts +29 -0
  58. package/dist/transcript-chunker.d.ts.map +1 -0
  59. package/dist/transcript-chunker.js +142 -0
  60. package/dist/transcript-chunker.js.map +1 -0
  61. package/dist/types.d.ts +122 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +71 -0
  64. package/dist/types.js.map +1 -0
  65. package/package.json +45 -0
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Pluggable chunker interface for splitting content into embeddable pieces.
3
+ *
4
+ * @module
5
+ */
6
+ /** A chunk of content produced by a {@link Chunker}. */
7
+ export interface Chunk {
8
+ /** The text content of this chunk. */
9
+ text: string;
10
+ /** Zero-based index of this chunk within the source content. */
11
+ index: number;
12
+ /** Optional metadata carried through from the source or added by the chunker. */
13
+ metadata?: Record<string, unknown>;
14
+ }
15
+ /** Splits content into chunks suitable for embedding. */
16
+ export interface Chunker {
17
+ /** Split content into one or more chunks. */
18
+ chunk(content: string, metadata?: Record<string, unknown>): Chunk[];
19
+ }
20
+ //# sourceMappingURL=chunker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunker.d.ts","sourceRoot":"","sources":["../src/chunker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wDAAwD;AACxD,MAAM,WAAW,KAAK;IACpB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,yDAAyD;AACzD,MAAM,WAAW,OAAO;IACtB,6CAA6C;IAC7C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,EAAE,CAAC;CACrE"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Pluggable chunker interface for splitting content into embeddable pieces.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=chunker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunker.js","sourceRoot":"","sources":["../src/chunker.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Neo4j driver singleton — connection management, health checks, and shutdown.
3
+ *
4
+ * Follows the same singleton pattern as `packages/server/src/db.ts`.
5
+ * Call {@link openNeo4j} once at startup, then use {@link getDriver} or
6
+ * {@link getSession} for queries, and {@link closeNeo4j} on shutdown.
7
+ *
8
+ * @module
9
+ */
10
+ import { type Driver, type Session } from "neo4j-driver";
11
+ /** Configuration for the Neo4j connection. */
12
+ export interface Neo4jClientConfig {
13
+ /** Bolt URL (default: bolt://127.0.0.1:7687). */
14
+ url?: string;
15
+ /** Username (default: neo4j). */
16
+ username?: string;
17
+ /** Password (default: grackle-dev). */
18
+ password?: string;
19
+ /** Neo4j database name (default: neo4j). */
20
+ database?: string;
21
+ }
22
+ /**
23
+ * Open a connection to Neo4j.
24
+ *
25
+ * Reads configuration from environment variables first, then from the
26
+ * provided {@link Neo4jClientConfig}, then from built-in defaults.
27
+ *
28
+ * Idempotent — returns silently if a connection is already open.
29
+ *
30
+ * | Env Variable | Fallback |
31
+ * |--------------------------|---------------------|
32
+ * | `GRACKLE_NEO4J_URL` | `config.url` |
33
+ * | `GRACKLE_NEO4J_USER` | `config.username` |
34
+ * | `GRACKLE_NEO4J_PASSWORD` | `config.password` |
35
+ * | `GRACKLE_NEO4J_DATABASE` | `config.database` |
36
+ */
37
+ export declare function openNeo4j(config?: Neo4jClientConfig): Promise<void>;
38
+ /**
39
+ * Get a Neo4j session for running queries.
40
+ *
41
+ * Sessions are lightweight and should be short-lived — open one per
42
+ * logical unit of work and close it when done.
43
+ *
44
+ * @throws If {@link openNeo4j} has not been called.
45
+ */
46
+ export declare function getSession(): Session;
47
+ /**
48
+ * Get the raw Neo4j driver instance.
49
+ *
50
+ * Prefer {@link getSession} for most use cases. Use the driver directly
51
+ * only when you need `driver.executeQuery()` for simple one-shot queries.
52
+ *
53
+ * @throws If {@link openNeo4j} has not been called.
54
+ */
55
+ export declare function getDriver(): Driver;
56
+ /**
57
+ * Check Neo4j connectivity.
58
+ *
59
+ * @returns `true` if the connection is healthy, `false` otherwise.
60
+ */
61
+ export declare function healthCheck(): Promise<boolean>;
62
+ /**
63
+ * Gracefully close the Neo4j connection and release resources.
64
+ *
65
+ * Safe to call multiple times or when no connection is open.
66
+ */
67
+ export declare function closeNeo4j(): Promise<void>;
68
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAc,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAehE,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAmBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBnE;AAgDD;;;;;;;GAOG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAKpC;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAKlC;AAED;;;;GAIG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAUpD;AAED;;;;GAIG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAYhD"}
package/dist/client.js ADDED
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Neo4j driver singleton — connection management, health checks, and shutdown.
3
+ *
4
+ * Follows the same singleton pattern as `packages/server/src/db.ts`.
5
+ * Call {@link openNeo4j} once at startup, then use {@link getDriver} or
6
+ * {@link getSession} for queries, and {@link closeNeo4j} on shutdown.
7
+ *
8
+ * @module
9
+ */
10
+ import neo4j from "neo4j-driver";
11
+ import { logger } from "./logger.js";
12
+ import { DEFAULT_NEO4J_URL, DEFAULT_NEO4J_USER, DEFAULT_NEO4J_PASSWORD, DEFAULT_NEO4J_DATABASE, NEO4J_MAX_POOL_SIZE, NEO4J_CONNECTION_ACQUISITION_TIMEOUT, } from "./constants.js";
13
+ // ---------------------------------------------------------------------------
14
+ // Singleton state
15
+ // ---------------------------------------------------------------------------
16
+ /** Module-level singleton driver instance. */
17
+ let driver;
18
+ /** Promise that resolves when initialization is complete (guards concurrent calls). */
19
+ let initPromise;
20
+ /** The database name used when creating sessions. */
21
+ let databaseName = DEFAULT_NEO4J_DATABASE;
22
+ // ---------------------------------------------------------------------------
23
+ // Public API
24
+ // ---------------------------------------------------------------------------
25
+ /**
26
+ * Open a connection to Neo4j.
27
+ *
28
+ * Reads configuration from environment variables first, then from the
29
+ * provided {@link Neo4jClientConfig}, then from built-in defaults.
30
+ *
31
+ * Idempotent — returns silently if a connection is already open.
32
+ *
33
+ * | Env Variable | Fallback |
34
+ * |--------------------------|---------------------|
35
+ * | `GRACKLE_NEO4J_URL` | `config.url` |
36
+ * | `GRACKLE_NEO4J_USER` | `config.username` |
37
+ * | `GRACKLE_NEO4J_PASSWORD` | `config.password` |
38
+ * | `GRACKLE_NEO4J_DATABASE` | `config.database` |
39
+ */
40
+ export function openNeo4j(config) {
41
+ if (driver) {
42
+ return Promise.resolve();
43
+ }
44
+ // Guard against concurrent calls: if an init is already in flight, await it.
45
+ if (initPromise) {
46
+ return initPromise;
47
+ }
48
+ // Wrap the async work so initPromise is cleared synchronously after settlement.
49
+ initPromise = doOpen(config).finally(() => {
50
+ initPromise = undefined;
51
+ });
52
+ return initPromise;
53
+ }
54
+ /**
55
+ * Internal init logic — separated so {@link openNeo4j} can guard concurrency
56
+ * with a shared promise.
57
+ */
58
+ async function doOpen(config) {
59
+ const url = process.env.GRACKLE_NEO4J_URL || config?.url || DEFAULT_NEO4J_URL;
60
+ const username = process.env.GRACKLE_NEO4J_USER || config?.username || DEFAULT_NEO4J_USER;
61
+ const explicitPassword = process.env.GRACKLE_NEO4J_PASSWORD || config?.password;
62
+ if (!explicitPassword && process.env.NODE_ENV === "production") {
63
+ throw new Error("GRACKLE_NEO4J_PASSWORD must be set in production. " +
64
+ "Refusing to use the default development password.");
65
+ }
66
+ const password = explicitPassword || DEFAULT_NEO4J_PASSWORD;
67
+ databaseName =
68
+ process.env.GRACKLE_NEO4J_DATABASE ||
69
+ config?.database ||
70
+ DEFAULT_NEO4J_DATABASE;
71
+ logger.info({ url, database: databaseName }, "Connecting to Neo4j");
72
+ const newDriver = neo4j.driver(url, neo4j.auth.basic(username, password), {
73
+ disableLosslessIntegers: true,
74
+ maxConnectionPoolSize: NEO4J_MAX_POOL_SIZE,
75
+ connectionAcquisitionTimeout: NEO4J_CONNECTION_ACQUISITION_TIMEOUT,
76
+ });
77
+ try {
78
+ await newDriver.verifyConnectivity({ database: databaseName });
79
+ logger.info("Neo4j connectivity verified");
80
+ }
81
+ catch (error) {
82
+ await newDriver.close().catch(() => { });
83
+ throw new Error(`Failed to connect to Neo4j at ${url}: ${error instanceof Error ? error.message : String(error)}. ` +
84
+ "Ensure Neo4j is running and the credentials are correct.", { cause: error });
85
+ }
86
+ driver = newDriver;
87
+ }
88
+ /**
89
+ * Get a Neo4j session for running queries.
90
+ *
91
+ * Sessions are lightweight and should be short-lived — open one per
92
+ * logical unit of work and close it when done.
93
+ *
94
+ * @throws If {@link openNeo4j} has not been called.
95
+ */
96
+ export function getSession() {
97
+ if (!driver) {
98
+ throw new Error("Neo4j not initialized. Call openNeo4j() first.");
99
+ }
100
+ return driver.session({ database: databaseName });
101
+ }
102
+ /**
103
+ * Get the raw Neo4j driver instance.
104
+ *
105
+ * Prefer {@link getSession} for most use cases. Use the driver directly
106
+ * only when you need `driver.executeQuery()` for simple one-shot queries.
107
+ *
108
+ * @throws If {@link openNeo4j} has not been called.
109
+ */
110
+ export function getDriver() {
111
+ if (!driver) {
112
+ throw new Error("Neo4j not initialized. Call openNeo4j() first.");
113
+ }
114
+ return driver;
115
+ }
116
+ /**
117
+ * Check Neo4j connectivity.
118
+ *
119
+ * @returns `true` if the connection is healthy, `false` otherwise.
120
+ */
121
+ export async function healthCheck() {
122
+ if (!driver) {
123
+ return false;
124
+ }
125
+ try {
126
+ await driver.verifyConnectivity({ database: databaseName });
127
+ return true;
128
+ }
129
+ catch {
130
+ return false;
131
+ }
132
+ }
133
+ /**
134
+ * Gracefully close the Neo4j connection and release resources.
135
+ *
136
+ * Safe to call multiple times or when no connection is open.
137
+ */
138
+ export async function closeNeo4j() {
139
+ // Wait for any in-flight initialization to settle before closing.
140
+ if (initPromise) {
141
+ await initPromise.catch(() => { });
142
+ }
143
+ const current = driver;
144
+ if (current) {
145
+ driver = undefined;
146
+ logger.info("Closing Neo4j connection");
147
+ await current.close();
148
+ }
149
+ }
150
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAoC,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,MAA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AC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS;IACvB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,kBAAkB,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,kEAAkE;IAClE,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC;IACvB,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,GAAG,SAAS,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACxC,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Constants for the Neo4j knowledge graph subsystem.
3
+ *
4
+ * @module
5
+ */
6
+ /** Default Neo4j Bolt connection URL. */
7
+ export declare const DEFAULT_NEO4J_URL: string;
8
+ /** Default Neo4j username. */
9
+ export declare const DEFAULT_NEO4J_USER: string;
10
+ /**
11
+ * Default Neo4j password (development only; production should always override).
12
+ *
13
+ * Not re-exported from the package barrel to avoid leaking a credential
14
+ * constant in the public API.
15
+ *
16
+ * @internal
17
+ */
18
+ export declare const DEFAULT_NEO4J_PASSWORD: string;
19
+ /** Default Neo4j database name. */
20
+ export declare const DEFAULT_NEO4J_DATABASE: string;
21
+ /** Maximum number of connections in the Neo4j driver pool. */
22
+ export declare const NEO4J_MAX_POOL_SIZE: number;
23
+ /** Timeout (ms) for acquiring a connection from the Neo4j pool. */
24
+ export declare const NEO4J_CONNECTION_ACQUISITION_TIMEOUT: number;
25
+ /** Neo4j node label applied to all knowledge graph nodes. */
26
+ export declare const NODE_LABEL: string;
27
+ /** Name of the vector index on knowledge node embeddings. */
28
+ export declare const VECTOR_INDEX_NAME: string;
29
+ /** Dimensionality of the embedding vectors (OpenAI text-embedding-3-small). */
30
+ export declare const EMBEDDING_DIMENSIONS: number;
31
+ /** Similarity function used by the vector index. */
32
+ export declare const VECTOR_SIMILARITY_FUNCTION: string;
33
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,yCAAyC;AACzC,eAAO,MAAM,iBAAiB,EAAE,MAAgC,CAAC;AAEjE,8BAA8B;AAC9B,eAAO,MAAM,kBAAkB,EAAE,MAAgB,CAAC;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAsB,CAAC;AAE5D,mCAAmC;AACnC,eAAO,MAAM,sBAAsB,EAAE,MAAgB,CAAC;AAEtD,8DAA8D;AAC9D,eAAO,MAAM,mBAAmB,EAAE,MAAW,CAAC;AAE9C,mEAAmE;AACnE,eAAO,MAAM,oCAAoC,EAAE,MAAe,CAAC;AAEnE,6DAA6D;AAC7D,eAAO,MAAM,UAAU,EAAE,MAAwB,CAAC;AAElD,6DAA6D;AAC7D,eAAO,MAAM,iBAAiB,EAAE,MAAoC,CAAC;AAErE,+EAA+E;AAC/E,eAAO,MAAM,oBAAoB,EAAE,MAAa,CAAC;AAEjD,oDAAoD;AACpD,eAAO,MAAM,0BAA0B,EAAE,MAAiB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Constants for the Neo4j knowledge graph subsystem.
3
+ *
4
+ * @module
5
+ */
6
+ /** Default Neo4j Bolt connection URL. */
7
+ export const DEFAULT_NEO4J_URL = "bolt://127.0.0.1:7687";
8
+ /** Default Neo4j username. */
9
+ export const DEFAULT_NEO4J_USER = "neo4j";
10
+ /**
11
+ * Default Neo4j password (development only; production should always override).
12
+ *
13
+ * Not re-exported from the package barrel to avoid leaking a credential
14
+ * constant in the public API.
15
+ *
16
+ * @internal
17
+ */
18
+ export const DEFAULT_NEO4J_PASSWORD = "grackle-dev";
19
+ /** Default Neo4j database name. */
20
+ export const DEFAULT_NEO4J_DATABASE = "neo4j";
21
+ /** Maximum number of connections in the Neo4j driver pool. */
22
+ export const NEO4J_MAX_POOL_SIZE = 50;
23
+ /** Timeout (ms) for acquiring a connection from the Neo4j pool. */
24
+ export const NEO4J_CONNECTION_ACQUISITION_TIMEOUT = 30_000;
25
+ /** Neo4j node label applied to all knowledge graph nodes. */
26
+ export const NODE_LABEL = "KnowledgeNode";
27
+ /** Name of the vector index on knowledge node embeddings. */
28
+ export const VECTOR_INDEX_NAME = "knowledge_embedding_index";
29
+ /** Dimensionality of the embedding vectors (OpenAI text-embedding-3-small). */
30
+ export const EMBEDDING_DIMENSIONS = 1536;
31
+ /** Similarity function used by the vector index. */
32
+ export const VECTOR_SIMILARITY_FUNCTION = "cosine";
33
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,yCAAyC;AACzC,MAAM,CAAC,MAAM,iBAAiB,GAAW,uBAAuB,CAAC;AAEjE,8BAA8B;AAC9B,MAAM,CAAC,MAAM,kBAAkB,GAAW,OAAO,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAW,aAAa,CAAC;AAE5D,mCAAmC;AACnC,MAAM,CAAC,MAAM,sBAAsB,GAAW,OAAO,CAAC;AAEtD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAW,EAAE,CAAC;AAE9C,mEAAmE;AACnE,MAAM,CAAC,MAAM,oCAAoC,GAAW,MAAM,CAAC;AAEnE,6DAA6D;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAW,eAAe,CAAC;AAElD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,iBAAiB,GAAW,2BAA2B,CAAC;AAErE,+EAA+E;AAC/E,MAAM,CAAC,MAAM,oBAAoB,GAAW,IAAI,CAAC;AAEjD,oDAAoD;AACpD,MAAM,CAAC,MAAM,0BAA0B,GAAW,QAAQ,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Edge CRUD operations for the knowledge graph.
3
+ *
4
+ * Provides create and remove operations for typed relationships between
5
+ * {@link KnowledgeNode} instances, backed by Neo4j.
6
+ *
7
+ * @module
8
+ */
9
+ import { type EdgeType, type KnowledgeEdge } from "./types.js";
10
+ /**
11
+ * Create a typed edge between two nodes.
12
+ *
13
+ * @param fromId - Source node ID.
14
+ * @param toId - Target node ID.
15
+ * @param type - Relationship type (must be a valid {@link EdgeType}).
16
+ * @param metadata - Optional metadata to attach to the edge.
17
+ * @returns The created edge.
18
+ * @throws If either node does not exist.
19
+ * @throws If the edge type is invalid.
20
+ */
21
+ export declare function createEdge(fromId: string, toId: string, type: EdgeType, metadata?: Record<string, unknown>): Promise<KnowledgeEdge>;
22
+ /**
23
+ * Remove an edge between two nodes.
24
+ *
25
+ * @param fromId - Source node ID.
26
+ * @param toId - Target node ID.
27
+ * @param type - Relationship type to remove.
28
+ * @returns `true` if an edge was removed, `false` if no matching edge existed.
29
+ * @throws If the edge type is invalid.
30
+ */
31
+ export declare function removeEdge(fromId: string, toId: string, type: EdgeType): Promise<boolean>;
32
+ //# sourceMappingURL=edge-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-store.d.ts","sourceRoot":"","sources":["../src/edge-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAa,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAwD1E;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,EACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,aAAa,CAAC,CAiDxB;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,OAAO,CAAC,CAsBlB"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Edge CRUD operations for the knowledge graph.
3
+ *
4
+ * Provides create and remove operations for typed relationships between
5
+ * {@link KnowledgeNode} instances, backed by Neo4j.
6
+ *
7
+ * @module
8
+ */
9
+ import { getSession } from "./client.js";
10
+ import { logger } from "./logger.js";
11
+ import { NODE_LABEL } from "./constants.js";
12
+ import { EDGE_TYPE } from "./types.js";
13
+ // ---------------------------------------------------------------------------
14
+ // Validation
15
+ // ---------------------------------------------------------------------------
16
+ /** Known edge type values for runtime validation. */
17
+ const VALID_EDGE_TYPES = new Set(Object.values(EDGE_TYPE));
18
+ /**
19
+ * Assert that a string is a valid {@link EdgeType}.
20
+ *
21
+ * @throws If the value is not a known edge type.
22
+ */
23
+ function assertValidEdgeType(type) {
24
+ if (!VALID_EDGE_TYPES.has(type)) {
25
+ throw new Error(`Invalid edge type: "${type}". Must be one of: ${[...VALID_EDGE_TYPES].join(", ")}`);
26
+ }
27
+ }
28
+ // ---------------------------------------------------------------------------
29
+ // Cypher builders
30
+ // ---------------------------------------------------------------------------
31
+ /**
32
+ * Build the Cypher query for creating an edge of a given type.
33
+ *
34
+ * Relationship types cannot be parameterized in Cypher, so the type is
35
+ * interpolated directly. This is safe because {@link assertValidEdgeType}
36
+ * ensures the value comes from the closed {@link EdgeType} union.
37
+ */
38
+ function buildCreateEdgeCypher(edgeType) {
39
+ return [
40
+ `MATCH (a:${NODE_LABEL} {id: $fromId}), (b:${NODE_LABEL} {id: $toId})`,
41
+ `CREATE (a)-[r:${edgeType} {metadata: $metadata, createdAt: $createdAt}]->(b)`,
42
+ `RETURN a.id AS fromId, b.id AS toId, type(r) AS type, r.metadata AS metadata, r.createdAt AS createdAt`,
43
+ ].join("\n");
44
+ }
45
+ /**
46
+ * Build the Cypher query for removing an edge of a given type.
47
+ */
48
+ function buildRemoveEdgeCypher(edgeType) {
49
+ return [
50
+ `MATCH (a:${NODE_LABEL} {id: $fromId})-[r:${edgeType}]->(b:${NODE_LABEL} {id: $toId})`,
51
+ `DELETE r`,
52
+ `RETURN count(r) AS deleted`,
53
+ ].join("\n");
54
+ }
55
+ // ---------------------------------------------------------------------------
56
+ // Public API
57
+ // ---------------------------------------------------------------------------
58
+ /**
59
+ * Create a typed edge between two nodes.
60
+ *
61
+ * @param fromId - Source node ID.
62
+ * @param toId - Target node ID.
63
+ * @param type - Relationship type (must be a valid {@link EdgeType}).
64
+ * @param metadata - Optional metadata to attach to the edge.
65
+ * @returns The created edge.
66
+ * @throws If either node does not exist.
67
+ * @throws If the edge type is invalid.
68
+ */
69
+ export async function createEdge(fromId, toId, type, metadata) {
70
+ assertValidEdgeType(type);
71
+ const createdAt = new Date().toISOString();
72
+ const metadataStr = metadata !== undefined ? JSON.stringify(metadata) : null;
73
+ const session = getSession();
74
+ try {
75
+ const result = await session.run(buildCreateEdgeCypher(type), {
76
+ fromId,
77
+ toId,
78
+ metadata: metadataStr,
79
+ createdAt,
80
+ });
81
+ if (result.records.length === 0) {
82
+ throw new Error(`Cannot create edge: one or both nodes not found (fromId=${fromId}, toId=${toId})`);
83
+ }
84
+ const record = result.records[0];
85
+ let parsedMetadata;
86
+ const rawMetadata = record.get("metadata");
87
+ if (rawMetadata !== null) {
88
+ try {
89
+ parsedMetadata = JSON.parse(rawMetadata);
90
+ }
91
+ catch {
92
+ parsedMetadata = undefined;
93
+ }
94
+ }
95
+ logger.debug({ fromId, toId, type }, "Created edge");
96
+ return {
97
+ fromId: record.get("fromId"),
98
+ toId: record.get("toId"),
99
+ type: record.get("type"),
100
+ metadata: parsedMetadata,
101
+ createdAt: record.get("createdAt"),
102
+ };
103
+ }
104
+ finally {
105
+ try {
106
+ await session.close();
107
+ }
108
+ catch (closeError) {
109
+ logger.warn({ err: closeError }, "Failed to close session after createEdge");
110
+ }
111
+ }
112
+ }
113
+ /**
114
+ * Remove an edge between two nodes.
115
+ *
116
+ * @param fromId - Source node ID.
117
+ * @param toId - Target node ID.
118
+ * @param type - Relationship type to remove.
119
+ * @returns `true` if an edge was removed, `false` if no matching edge existed.
120
+ * @throws If the edge type is invalid.
121
+ */
122
+ export async function removeEdge(fromId, toId, type) {
123
+ assertValidEdgeType(type);
124
+ const session = getSession();
125
+ try {
126
+ const result = await session.run(buildRemoveEdgeCypher(type), {
127
+ fromId,
128
+ toId,
129
+ });
130
+ const deleted = result.records[0]?.get("deleted");
131
+ if (deleted > 0) {
132
+ logger.debug({ fromId, toId, type }, "Removed edge");
133
+ }
134
+ return deleted > 0;
135
+ }
136
+ finally {
137
+ try {
138
+ await session.close();
139
+ }
140
+ catch (closeError) {
141
+ logger.warn({ err: closeError }, "Failed to close session after removeEdge");
142
+ }
143
+ }
144
+ }
145
+ //# sourceMappingURL=edge-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-store.js","sourceRoot":"","sources":["../src/edge-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAA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C;QACT,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,0CAA0C,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,IAAY,EACZ,IAAc;IAEd,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAE1B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE;YAC5D,MAAM;YACN,IAAI;SACL,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAW,CAAC;QAC5D,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,OAAO,GAAG,CAAC,CAAC;IACrB,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,0CAA0C,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Pluggable embedder interface for converting text into vector embeddings.
3
+ *
4
+ * @module
5
+ */
6
+ /** A single embedding result pairing input text with its vector. */
7
+ export interface EmbeddingResult {
8
+ /** The input text that was embedded. */
9
+ text: string;
10
+ /** The embedding vector (array of floats). */
11
+ vector: number[];
12
+ }
13
+ /** Configuration for creating an {@link Embedder}. */
14
+ export interface EmbedderOptions {
15
+ /** HuggingFace model ID (e.g., `"Xenova/all-MiniLM-L6-v2"`). */
16
+ modelId?: string;
17
+ /** Expected embedding dimensions. Used for validation when set. */
18
+ dimensions?: number;
19
+ }
20
+ /** Converts text into embedding vectors for semantic search and similarity. */
21
+ export interface Embedder {
22
+ /** Embed a single text string. */
23
+ embed(text: string): Promise<EmbeddingResult>;
24
+ /** Embed multiple texts in batch. */
25
+ embedBatch(texts: string[]): Promise<EmbeddingResult[]>;
26
+ /**
27
+ * The dimensionality of vectors produced by this embedder.
28
+ *
29
+ * When using a custom model without specifying `dimensions` in options,
30
+ * this value is `0` until the first embedding is computed. A value of `0`
31
+ * means the true dimensions are not yet known.
32
+ */
33
+ readonly dimensions: number;
34
+ }
35
+ //# sourceMappingURL=embedder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedder.d.ts","sourceRoot":"","sources":["../src/embedder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oEAAoE;AACpE,MAAM,WAAW,eAAe;IAC9B,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,sDAAsD;AACtD,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,kCAAkC;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9C,qCAAqC;IACrC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IACxD;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Pluggable embedder interface for converting text into vector embeddings.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=embedder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedder.js","sourceRoot":"","sources":["../src/embedder.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Graph expansion — traverse the knowledge graph from a starting node
3
+ * to discover connected nodes within N hops.
4
+ *
5
+ * @module
6
+ */
7
+ import type { KnowledgeNode, KnowledgeEdge, EdgeType } from "./types.js";
8
+ import type { SearchResult } from "./search.js";
9
+ /** Options for graph expansion. */
10
+ export interface ExpandOptions {
11
+ /** Max traversal depth (default 1). */
12
+ depth?: number;
13
+ /** Only follow edges of these types. If empty/undefined, follow all. */
14
+ edgeTypes?: EdgeType[];
15
+ }
16
+ /** Result of a graph expansion: the subgraph reachable from the starting node(s). */
17
+ export interface ExpansionResult {
18
+ /** All neighbor nodes found (deduplicated), excluding the start node(s). */
19
+ nodes: KnowledgeNode[];
20
+ /** All edges traversed. */
21
+ edges: KnowledgeEdge[];
22
+ }
23
+ /**
24
+ * Expand a single node: return its neighbors within N hops.
25
+ *
26
+ * @param nodeId - The starting node ID.
27
+ * @param options - Traversal depth and optional edge type filter.
28
+ * @returns Neighbor nodes and traversed edges (deduplicated).
29
+ */
30
+ export declare function expandNode(nodeId: string, options?: ExpandOptions): Promise<ExpansionResult>;
31
+ /**
32
+ * Expand search results: return neighbors of all result nodes, deduplicated.
33
+ *
34
+ * Runs {@link expandNode} for each search result and merges the subgraphs,
35
+ * excluding the original search result nodes from the neighbor list.
36
+ *
37
+ * @param results - Search results from {@link knowledgeSearch}.
38
+ * @param options - Traversal depth and optional edge type filter.
39
+ * @returns Combined neighbor nodes and edges from all start nodes.
40
+ */
41
+ export declare function expandResults(results: SearchResult[], options?: ExpandOptions): Promise<ExpansionResult>;
42
+ //# sourceMappingURL=expand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expand.d.ts","sourceRoot":"","sources":["../src/expand.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhD,mCAAmC;AACnC,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;CACxB;AAED,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,4EAA4E;IAC5E,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,2BAA2B;IAC3B,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAiFD;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,eAAe,CAAC,CA8C1B;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,eAAe,CAAC,CAiB1B"}