@langchain/neo4j 0.0.1

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  4. package/dist/chains/graph_qa/cypher.cjs +117 -0
  5. package/dist/chains/graph_qa/cypher.cjs.map +1 -0
  6. package/dist/chains/graph_qa/cypher.d.cts +73 -0
  7. package/dist/chains/graph_qa/cypher.d.cts.map +1 -0
  8. package/dist/chains/graph_qa/cypher.d.ts +73 -0
  9. package/dist/chains/graph_qa/cypher.d.ts.map +1 -0
  10. package/dist/chains/graph_qa/cypher.js +115 -0
  11. package/dist/chains/graph_qa/cypher.js.map +1 -0
  12. package/dist/chains/graph_qa/index.cjs +2 -0
  13. package/dist/chains/graph_qa/index.d.ts +2 -0
  14. package/dist/chains/graph_qa/index.js +3 -0
  15. package/dist/chains/graph_qa/prompts.cjs +42 -0
  16. package/dist/chains/graph_qa/prompts.cjs.map +1 -0
  17. package/dist/chains/graph_qa/prompts.d.cts +14 -0
  18. package/dist/chains/graph_qa/prompts.d.cts.map +1 -0
  19. package/dist/chains/graph_qa/prompts.d.ts +14 -0
  20. package/dist/chains/graph_qa/prompts.d.ts.map +1 -0
  21. package/dist/chains/graph_qa/prompts.js +40 -0
  22. package/dist/chains/graph_qa/prompts.js.map +1 -0
  23. package/dist/graphs/document.cjs +63 -0
  24. package/dist/graphs/document.cjs.map +1 -0
  25. package/dist/graphs/document.d.cts +56 -0
  26. package/dist/graphs/document.d.cts.map +1 -0
  27. package/dist/graphs/document.d.ts +56 -0
  28. package/dist/graphs/document.d.ts.map +1 -0
  29. package/dist/graphs/document.js +60 -0
  30. package/dist/graphs/document.js.map +1 -0
  31. package/dist/graphs/index.cjs +3 -0
  32. package/dist/graphs/index.d.ts +3 -0
  33. package/dist/graphs/index.js +4 -0
  34. package/dist/graphs/memgraph_graph.cjs +74 -0
  35. package/dist/graphs/memgraph_graph.cjs.map +1 -0
  36. package/dist/graphs/memgraph_graph.d.cts +36 -0
  37. package/dist/graphs/memgraph_graph.d.cts.map +1 -0
  38. package/dist/graphs/memgraph_graph.d.ts +36 -0
  39. package/dist/graphs/memgraph_graph.d.ts.map +1 -0
  40. package/dist/graphs/memgraph_graph.js +74 -0
  41. package/dist/graphs/memgraph_graph.js.map +1 -0
  42. package/dist/graphs/neo4j_graph.cjs +429 -0
  43. package/dist/graphs/neo4j_graph.cjs.map +1 -0
  44. package/dist/graphs/neo4j_graph.d.cts +96 -0
  45. package/dist/graphs/neo4j_graph.d.cts.map +1 -0
  46. package/dist/graphs/neo4j_graph.d.ts +96 -0
  47. package/dist/graphs/neo4j_graph.d.ts.map +1 -0
  48. package/dist/graphs/neo4j_graph.js +425 -0
  49. package/dist/graphs/neo4j_graph.js.map +1 -0
  50. package/dist/index.cjs +28 -0
  51. package/dist/index.d.cts +8 -0
  52. package/dist/index.d.ts +8 -0
  53. package/dist/index.js +12 -0
  54. package/dist/stores/message/index.cjs +1 -0
  55. package/dist/stores/message/index.d.ts +1 -0
  56. package/dist/stores/message/index.js +2 -0
  57. package/dist/stores/message/neo4j.cjs +114 -0
  58. package/dist/stores/message/neo4j.cjs.map +1 -0
  59. package/dist/stores/message/neo4j.d.cts +40 -0
  60. package/dist/stores/message/neo4j.d.cts.map +1 -0
  61. package/dist/stores/message/neo4j.d.ts +40 -0
  62. package/dist/stores/message/neo4j.d.ts.map +1 -0
  63. package/dist/stores/message/neo4j.js +112 -0
  64. package/dist/stores/message/neo4j.js.map +1 -0
  65. package/dist/vectorstores/index.cjs +1 -0
  66. package/dist/vectorstores/index.d.ts +1 -0
  67. package/dist/vectorstores/index.js +2 -0
  68. package/dist/vectorstores/neo4j_vector.cjs +622 -0
  69. package/dist/vectorstores/neo4j_vector.cjs.map +1 -0
  70. package/dist/vectorstores/neo4j_vector.d.cts +96 -0
  71. package/dist/vectorstores/neo4j_vector.d.cts.map +1 -0
  72. package/dist/vectorstores/neo4j_vector.d.ts +96 -0
  73. package/dist/vectorstores/neo4j_vector.d.ts.map +1 -0
  74. package/dist/vectorstores/neo4j_vector.js +616 -0
  75. package/dist/vectorstores/neo4j_vector.js.map +1 -0
  76. package/package.json +98 -0
@@ -0,0 +1,115 @@
1
+ import { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT } from "./prompts.js";
2
+ import { BaseChain, LLMChain } from "@langchain/classic/chains";
3
+ //#region src/chains/graph_qa/cypher.ts
4
+ const INTERMEDIATE_STEPS_KEY = "intermediateSteps";
5
+ /**
6
+ * Chain for question-answering against a graph by generating Cypher statements.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const chain = new GraphCypherQAChain({
11
+ * llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
12
+ * graph: new Neo4jGraph(),
13
+ * });
14
+ * const res = await chain.invoke("Who played in Pulp Fiction?");
15
+ * ```
16
+ *
17
+ * @security
18
+ * This chain will execute Cypher statements against the provided database.
19
+ * Make sure that the database connection uses credentials
20
+ * that are narrowly-scoped to only include necessary permissions.
21
+ * Failure to do so may result in data corruption or loss, since the calling code
22
+ * may attempt commands that would result in deletion, mutation of data
23
+ * if appropriately prompted or reading sensitive data if such data is present in the database.
24
+ * The best way to guard against such negative outcomes is to (as appropriate) limit the
25
+ * permissions granted to the credentials used with this tool.
26
+ *
27
+ * See https://js.langchain.com/docs/security for more information.
28
+ */
29
+ var GraphCypherQAChain = class GraphCypherQAChain extends BaseChain {
30
+ graph;
31
+ cypherGenerationChain;
32
+ qaChain;
33
+ inputKey = "query";
34
+ outputKey = "result";
35
+ topK = 10;
36
+ returnDirect = false;
37
+ returnIntermediateSteps = false;
38
+ constructor(props) {
39
+ super(props);
40
+ const { graph, cypherGenerationChain, qaChain, inputKey, outputKey, topK, returnIntermediateSteps, returnDirect } = props;
41
+ this.graph = graph;
42
+ this.cypherGenerationChain = cypherGenerationChain;
43
+ this.qaChain = qaChain;
44
+ if (inputKey) this.inputKey = inputKey;
45
+ if (outputKey) this.outputKey = outputKey;
46
+ if (topK) this.topK = topK;
47
+ if (returnIntermediateSteps) this.returnIntermediateSteps = returnIntermediateSteps;
48
+ if (returnDirect) this.returnDirect = returnDirect;
49
+ }
50
+ _chainType() {
51
+ return "graph_cypher_chain";
52
+ }
53
+ get inputKeys() {
54
+ return [this.inputKey];
55
+ }
56
+ get outputKeys() {
57
+ return [this.outputKey];
58
+ }
59
+ static fromLLM(props) {
60
+ const { graph, qaPrompt = CYPHER_QA_PROMPT, cypherPrompt = CYPHER_GENERATION_PROMPT, llm, cypherLLM, qaLLM, returnIntermediateSteps = false, returnDirect = false } = props;
61
+ if (!cypherLLM && !llm) throw new Error("Either 'llm' or 'cypherLLM' parameters must be provided");
62
+ if (!qaLLM && !llm) throw new Error("Either 'llm' or 'qaLLM' parameters must be provided");
63
+ if (cypherLLM && qaLLM && llm) throw new Error("You can specify up to two of 'cypherLLM', 'qaLLM', and 'llm', but not all three simultaneously.");
64
+ const qaChain = new LLMChain({
65
+ llm: qaLLM || llm,
66
+ prompt: qaPrompt
67
+ });
68
+ return new GraphCypherQAChain({
69
+ cypherGenerationChain: new LLMChain({
70
+ llm: cypherLLM || llm,
71
+ prompt: cypherPrompt
72
+ }),
73
+ qaChain,
74
+ graph,
75
+ returnIntermediateSteps,
76
+ returnDirect
77
+ });
78
+ }
79
+ extractCypher(text) {
80
+ const matches = text.match(/```(.*?)```/s);
81
+ return matches ? matches[1] : text;
82
+ }
83
+ async _call(values, runManager) {
84
+ const callbacks = runManager?.getChild();
85
+ const question = values[this.inputKey];
86
+ const intermediateSteps = [];
87
+ const generatedCypher = await this.cypherGenerationChain.call({
88
+ question,
89
+ schema: this.graph.getSchema()
90
+ }, callbacks);
91
+ const extractedCypher = this.extractCypher(generatedCypher.text);
92
+ await runManager?.handleText(`Generated Cypher:\n`);
93
+ await runManager?.handleText(`${extractedCypher} green\n`);
94
+ intermediateSteps.push({ query: extractedCypher });
95
+ let chainResult;
96
+ const context = await this.graph.query(extractedCypher, { topK: this.topK });
97
+ if (this.returnDirect) chainResult = { [this.outputKey]: context };
98
+ else {
99
+ await runManager?.handleText("Full Context:\n");
100
+ await runManager?.handleText(`${context} green\n`);
101
+ intermediateSteps.push({ context });
102
+ const result = await this.qaChain.call({
103
+ question,
104
+ context: JSON.stringify(context)
105
+ }, callbacks);
106
+ chainResult = { [this.outputKey]: result[this.qaChain.outputKey] };
107
+ }
108
+ if (this.returnIntermediateSteps) chainResult[INTERMEDIATE_STEPS_KEY] = intermediateSteps;
109
+ return chainResult;
110
+ }
111
+ };
112
+ //#endregion
113
+ export { GraphCypherQAChain, INTERMEDIATE_STEPS_KEY };
114
+
115
+ //# sourceMappingURL=cypher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cypher.js","names":[],"sources":["../../../src/chains/graph_qa/cypher.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { ChainValues } from \"@langchain/core/utils/types\";\nimport { BasePromptTemplate } from \"@langchain/core/prompts\";\nimport { CallbackManagerForChainRun } from \"@langchain/core/callbacks/manager\";\nimport { LLMChain, BaseChain, ChainInputs } from \"@langchain/classic/chains\";\nimport { Neo4jGraph } from \"../../graphs/neo4j_graph.js\";\nimport { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT } from \"./prompts.js\";\n\nexport const INTERMEDIATE_STEPS_KEY = \"intermediateSteps\";\n\nexport interface GraphCypherQAChainInput extends ChainInputs {\n graph: Neo4jGraph;\n cypherGenerationChain: LLMChain;\n qaChain: LLMChain;\n inputKey?: string;\n outputKey?: string;\n topK?: number;\n returnIntermediateSteps?: boolean;\n returnDirect?: boolean;\n}\n\nexport interface FromLLMInput {\n graph: Neo4jGraph;\n llm?: BaseLanguageModelInterface;\n cypherLLM?: BaseLanguageModelInterface;\n qaLLM?: BaseLanguageModelInterface;\n qaPrompt?: BasePromptTemplate;\n cypherPrompt?: BasePromptTemplate;\n returnIntermediateSteps?: boolean;\n returnDirect?: boolean;\n}\n\n/**\n * Chain for question-answering against a graph by generating Cypher statements.\n *\n * @example\n * ```typescript\n * const chain = new GraphCypherQAChain({\n * llm: new ChatOpenAI({ model: \"gpt-4o-mini\", temperature: 0 }),\n * graph: new Neo4jGraph(),\n * });\n * const res = await chain.invoke(\"Who played in Pulp Fiction?\");\n * ```\n *\n * @security\n * This chain will execute Cypher statements against the provided database.\n * Make sure that the database connection uses credentials\n * that are narrowly-scoped to only include necessary permissions.\n * Failure to do so may result in data corruption or loss, since the calling code\n * may attempt commands that would result in deletion, mutation of data\n * if appropriately prompted or reading sensitive data if such data is present in the database.\n * The best way to guard against such negative outcomes is to (as appropriate) limit the\n * permissions granted to the credentials used with this tool.\n *\n * See https://js.langchain.com/docs/security for more information.\n */\nexport class GraphCypherQAChain extends BaseChain {\n private graph: Neo4jGraph;\n\n private cypherGenerationChain: LLMChain;\n\n private qaChain: LLMChain;\n\n private inputKey = \"query\";\n\n private outputKey = \"result\";\n\n private topK = 10;\n\n private returnDirect = false;\n\n private returnIntermediateSteps = false;\n\n constructor(props: GraphCypherQAChainInput) {\n super(props);\n const {\n graph,\n cypherGenerationChain,\n qaChain,\n inputKey,\n outputKey,\n topK,\n returnIntermediateSteps,\n returnDirect,\n } = props;\n\n this.graph = graph;\n this.cypherGenerationChain = cypherGenerationChain;\n this.qaChain = qaChain;\n\n if (inputKey) {\n this.inputKey = inputKey;\n }\n if (outputKey) {\n this.outputKey = outputKey;\n }\n if (topK) {\n this.topK = topK;\n }\n if (returnIntermediateSteps) {\n this.returnIntermediateSteps = returnIntermediateSteps;\n }\n if (returnDirect) {\n this.returnDirect = returnDirect;\n }\n }\n\n _chainType() {\n return \"graph_cypher_chain\" as const;\n }\n\n get inputKeys(): string[] {\n return [this.inputKey];\n }\n\n get outputKeys(): string[] {\n return [this.outputKey];\n }\n\n static fromLLM(props: FromLLMInput): GraphCypherQAChain {\n const {\n graph,\n qaPrompt = CYPHER_QA_PROMPT,\n cypherPrompt = CYPHER_GENERATION_PROMPT,\n llm,\n cypherLLM,\n qaLLM,\n returnIntermediateSteps = false,\n returnDirect = false,\n } = props;\n\n if (!cypherLLM && !llm) {\n throw new Error(\n \"Either 'llm' or 'cypherLLM' parameters must be provided\"\n );\n }\n\n if (!qaLLM && !llm) {\n throw new Error(\"Either 'llm' or 'qaLLM' parameters must be provided\");\n }\n\n if (cypherLLM && qaLLM && llm) {\n throw new Error(\n \"You can specify up to two of 'cypherLLM', 'qaLLM', and 'llm', but not all three simultaneously.\"\n );\n }\n\n const qaChain = new LLMChain({\n llm: (qaLLM || llm) as BaseLanguageModelInterface,\n prompt: qaPrompt,\n });\n\n const cypherGenerationChain = new LLMChain({\n llm: (cypherLLM || llm) as BaseLanguageModelInterface,\n prompt: cypherPrompt,\n });\n\n return new GraphCypherQAChain({\n cypherGenerationChain,\n qaChain,\n graph,\n returnIntermediateSteps,\n returnDirect,\n });\n }\n\n private extractCypher(text: string): string {\n const pattern = /```(.*?)```/s;\n const matches = text.match(pattern);\n return matches ? matches[1] : text;\n }\n\n async _call(\n values: ChainValues,\n runManager?: CallbackManagerForChainRun\n ): Promise<ChainValues> {\n const callbacks = runManager?.getChild();\n const question = values[this.inputKey];\n\n const intermediateSteps = [];\n\n const generatedCypher = await this.cypherGenerationChain.call(\n { question, schema: this.graph.getSchema() },\n callbacks\n );\n\n const extractedCypher = this.extractCypher(generatedCypher.text);\n\n await runManager?.handleText(`Generated Cypher:\\n`);\n await runManager?.handleText(`${extractedCypher} green\\n`);\n\n intermediateSteps.push({ query: extractedCypher });\n\n let chainResult: ChainValues;\n const context = await this.graph.query(extractedCypher, {\n topK: this.topK,\n });\n\n if (this.returnDirect) {\n chainResult = { [this.outputKey]: context };\n } else {\n await runManager?.handleText(\"Full Context:\\n\");\n await runManager?.handleText(`${context} green\\n`);\n\n intermediateSteps.push({ context });\n\n const result = await this.qaChain.call(\n { question, context: JSON.stringify(context) },\n callbacks\n );\n\n chainResult = {\n [this.outputKey]: result[this.qaChain.outputKey],\n };\n }\n\n if (this.returnIntermediateSteps) {\n chainResult[INTERMEDIATE_STEPS_KEY] = intermediateSteps;\n }\n\n return chainResult;\n }\n}\n"],"mappings":";;;AAQA,MAAa,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;AAgDtC,IAAa,qBAAb,MAAa,2BAA2B,UAAU;CAChD;CAEA;CAEA;CAEA,WAAmB;CAEnB,YAAoB;CAEpB,OAAe;CAEf,eAAuB;CAEvB,0BAAkC;CAElC,YAAY,OAAgC;AAC1C,QAAM,MAAM;EACZ,MAAM,EACJ,OACA,uBACA,SACA,UACA,WACA,MACA,yBACA,iBACE;AAEJ,OAAK,QAAQ;AACb,OAAK,wBAAwB;AAC7B,OAAK,UAAU;AAEf,MAAI,SACF,MAAK,WAAW;AAElB,MAAI,UACF,MAAK,YAAY;AAEnB,MAAI,KACF,MAAK,OAAO;AAEd,MAAI,wBACF,MAAK,0BAA0B;AAEjC,MAAI,aACF,MAAK,eAAe;;CAIxB,aAAa;AACX,SAAO;;CAGT,IAAI,YAAsB;AACxB,SAAO,CAAC,KAAK,SAAS;;CAGxB,IAAI,aAAuB;AACzB,SAAO,CAAC,KAAK,UAAU;;CAGzB,OAAO,QAAQ,OAAyC;EACtD,MAAM,EACJ,OACA,WAAW,kBACX,eAAe,0BACf,KACA,WACA,OACA,0BAA0B,OAC1B,eAAe,UACb;AAEJ,MAAI,CAAC,aAAa,CAAC,IACjB,OAAM,IAAI,MACR,0DACD;AAGH,MAAI,CAAC,SAAS,CAAC,IACb,OAAM,IAAI,MAAM,sDAAsD;AAGxE,MAAI,aAAa,SAAS,IACxB,OAAM,IAAI,MACR,kGACD;EAGH,MAAM,UAAU,IAAI,SAAS;GAC3B,KAAM,SAAS;GACf,QAAQ;GACT,CAAC;AAOF,SAAO,IAAI,mBAAmB;GAC5B,uBAN4B,IAAI,SAAS;IACzC,KAAM,aAAa;IACnB,QAAQ;IACT,CAAC;GAIA;GACA;GACA;GACA;GACD,CAAC;;CAGJ,cAAsB,MAAsB;EAE1C,MAAM,UAAU,KAAK,MADL,eACmB;AACnC,SAAO,UAAU,QAAQ,KAAK;;CAGhC,MAAM,MACJ,QACA,YACsB;EACtB,MAAM,YAAY,YAAY,UAAU;EACxC,MAAM,WAAW,OAAO,KAAK;EAE7B,MAAM,oBAAoB,EAAE;EAE5B,MAAM,kBAAkB,MAAM,KAAK,sBAAsB,KACvD;GAAE;GAAU,QAAQ,KAAK,MAAM,WAAW;GAAE,EAC5C,UACD;EAED,MAAM,kBAAkB,KAAK,cAAc,gBAAgB,KAAK;AAEhE,QAAM,YAAY,WAAW,sBAAsB;AACnD,QAAM,YAAY,WAAW,GAAG,gBAAgB,UAAU;AAE1D,oBAAkB,KAAK,EAAE,OAAO,iBAAiB,CAAC;EAElD,IAAI;EACJ,MAAM,UAAU,MAAM,KAAK,MAAM,MAAM,iBAAiB,EACtD,MAAM,KAAK,MACZ,CAAC;AAEF,MAAI,KAAK,aACP,eAAc,GAAG,KAAK,YAAY,SAAS;OACtC;AACL,SAAM,YAAY,WAAW,kBAAkB;AAC/C,SAAM,YAAY,WAAW,GAAG,QAAQ,UAAU;AAElD,qBAAkB,KAAK,EAAE,SAAS,CAAC;GAEnC,MAAM,SAAS,MAAM,KAAK,QAAQ,KAChC;IAAE;IAAU,SAAS,KAAK,UAAU,QAAQ;IAAE,EAC9C,UACD;AAED,iBAAc,GACX,KAAK,YAAY,OAAO,KAAK,QAAQ,YACvC;;AAGH,MAAI,KAAK,wBACP,aAAY,0BAA0B;AAGxC,SAAO"}
@@ -0,0 +1,2 @@
1
+ require("./prompts.cjs");
2
+ require("./cypher.cjs");
@@ -0,0 +1,2 @@
1
+ import { FromLLMInput, GraphCypherQAChain, GraphCypherQAChainInput, INTERMEDIATE_STEPS_KEY } from "./cypher.js";
2
+ import { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT } from "./prompts.js";
@@ -0,0 +1,3 @@
1
+ import "./prompts.js";
2
+ import "./cypher.js";
3
+ export {};
@@ -0,0 +1,42 @@
1
+ require("../../_virtual/_rolldown/runtime.cjs");
2
+ let _langchain_core_prompts = require("@langchain/core/prompts");
3
+ const CYPHER_GENERATION_PROMPT = /* @__PURE__ */ new _langchain_core_prompts.PromptTemplate({
4
+ template: `Task:Generate Cypher statement to query a graph database.
5
+ Instructions:
6
+ Use only the provided relationship types and properties in the schema.
7
+ Do not use any other relationship types or properties that are not provided.
8
+ Schema:
9
+ {schema}
10
+ Note: Do not include any explanations or apologies in your responses.
11
+ Do not respond to any questions that might ask anything else than for you to construct a Cypher statement.
12
+ Do not include any text except the generated Cypher statement.
13
+
14
+ The question is:
15
+ {question}`,
16
+ inputVariables: ["schema", "question"]
17
+ });
18
+ const CYPHER_QA_PROMPT = /* @__PURE__ */ new _langchain_core_prompts.PromptTemplate({
19
+ template: `You are an assistant that helps to form nice and human understandable answers.
20
+ The information part contains the provided information that you must use to construct an answer.
21
+ The provided information is authoritative, you must never doubt it or try to use your internal knowledge to correct it.
22
+ Make the answer sound as a response to the question. Do not mention that you based the result on the given information.
23
+ Here is an example:
24
+
25
+ Question: Which managers own Neo4j stocks?
26
+ Context:[manager:CTL LLC, manager:JANE STREET GROUP LLC]
27
+ Helpful Answer: CTL LLC, JANE STREET GROUP LLC owns Neo4j stocks.
28
+
29
+ Follow this example when generating answers.
30
+ If the provided information is empty, say that you don't know the answer.
31
+ Information:
32
+ {context}
33
+
34
+ Question: {question}
35
+ Helpful Answer:`,
36
+ inputVariables: ["context", "question"]
37
+ });
38
+ //#endregion
39
+ exports.CYPHER_GENERATION_PROMPT = CYPHER_GENERATION_PROMPT;
40
+ exports.CYPHER_QA_PROMPT = CYPHER_QA_PROMPT;
41
+
42
+ //# sourceMappingURL=prompts.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.cjs","names":["PromptTemplate"],"sources":["../../../src/chains/graph_qa/prompts.ts"],"sourcesContent":["import { PromptTemplate } from \"@langchain/core/prompts\";\n\nconst CYPHER_GENERATION_TEMPLATE = `Task:Generate Cypher statement to query a graph database.\nInstructions:\nUse only the provided relationship types and properties in the schema.\nDo not use any other relationship types or properties that are not provided.\nSchema:\n{schema}\nNote: Do not include any explanations or apologies in your responses.\nDo not respond to any questions that might ask anything else than for you to construct a Cypher statement.\nDo not include any text except the generated Cypher statement.\n\nThe question is:\n{question}`;\nexport const CYPHER_GENERATION_PROMPT = /* #__PURE__ */ new PromptTemplate({\n template: CYPHER_GENERATION_TEMPLATE,\n inputVariables: [\"schema\", \"question\"],\n});\n\nconst CYPHER_QA_TEMPLATE = `You are an assistant that helps to form nice and human understandable answers.\nThe information part contains the provided information that you must use to construct an answer.\nThe provided information is authoritative, you must never doubt it or try to use your internal knowledge to correct it.\nMake the answer sound as a response to the question. Do not mention that you based the result on the given information.\nHere is an example:\n\nQuestion: Which managers own Neo4j stocks?\nContext:[manager:CTL LLC, manager:JANE STREET GROUP LLC]\nHelpful Answer: CTL LLC, JANE STREET GROUP LLC owns Neo4j stocks.\n\nFollow this example when generating answers.\nIf the provided information is empty, say that you don't know the answer.\nInformation:\n{context}\n\nQuestion: {question}\nHelpful Answer:`;\nexport const CYPHER_QA_PROMPT = /* #__PURE__ */ new PromptTemplate({\n template: CYPHER_QA_TEMPLATE,\n inputVariables: [\"context\", \"question\"],\n});\n"],"mappings":";;AAcA,MAAa,2CAA2C,IAAIA,wBAAAA,eAAe;CACzE,UAbiC;;;;;;;;;;;;CAcjC,gBAAgB,CAAC,UAAU,WAAW;CACvC,CAAC;AAmBF,MAAa,mCAAmC,IAAIA,wBAAAA,eAAe;CACjE,UAlByB;;;;;;;;;;;;;;;;;CAmBzB,gBAAgB,CAAC,WAAW,WAAW;CACxC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { PromptTemplate } from "@langchain/core/prompts";
2
+
3
+ //#region src/chains/graph_qa/prompts.d.ts
4
+ declare const CYPHER_GENERATION_PROMPT: PromptTemplate<{
5
+ question: any;
6
+ schema: any;
7
+ }, any>;
8
+ declare const CYPHER_QA_PROMPT: PromptTemplate<{
9
+ context: any;
10
+ question: any;
11
+ }, any>;
12
+ //#endregion
13
+ export { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT };
14
+ //# sourceMappingURL=prompts.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.d.cts","names":[],"sources":["../../../src/chains/graph_qa/prompts.ts"],"mappings":";;;cAca,wBAAA,EAAwB,cAAA;;;;cAsBxB,gBAAA,EAAgB,cAAA"}
@@ -0,0 +1,14 @@
1
+ import { PromptTemplate } from "@langchain/core/prompts";
2
+
3
+ //#region src/chains/graph_qa/prompts.d.ts
4
+ declare const CYPHER_GENERATION_PROMPT: PromptTemplate<{
5
+ question: any;
6
+ schema: any;
7
+ }, any>;
8
+ declare const CYPHER_QA_PROMPT: PromptTemplate<{
9
+ context: any;
10
+ question: any;
11
+ }, any>;
12
+ //#endregion
13
+ export { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT };
14
+ //# sourceMappingURL=prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.d.ts","names":[],"sources":["../../../src/chains/graph_qa/prompts.ts"],"mappings":";;;cAca,wBAAA,EAAwB,cAAA;;;;cAsBxB,gBAAA,EAAgB,cAAA"}
@@ -0,0 +1,40 @@
1
+ import { PromptTemplate } from "@langchain/core/prompts";
2
+ const CYPHER_GENERATION_PROMPT = /* @__PURE__ */ new PromptTemplate({
3
+ template: `Task:Generate Cypher statement to query a graph database.
4
+ Instructions:
5
+ Use only the provided relationship types and properties in the schema.
6
+ Do not use any other relationship types or properties that are not provided.
7
+ Schema:
8
+ {schema}
9
+ Note: Do not include any explanations or apologies in your responses.
10
+ Do not respond to any questions that might ask anything else than for you to construct a Cypher statement.
11
+ Do not include any text except the generated Cypher statement.
12
+
13
+ The question is:
14
+ {question}`,
15
+ inputVariables: ["schema", "question"]
16
+ });
17
+ const CYPHER_QA_PROMPT = /* @__PURE__ */ new PromptTemplate({
18
+ template: `You are an assistant that helps to form nice and human understandable answers.
19
+ The information part contains the provided information that you must use to construct an answer.
20
+ The provided information is authoritative, you must never doubt it or try to use your internal knowledge to correct it.
21
+ Make the answer sound as a response to the question. Do not mention that you based the result on the given information.
22
+ Here is an example:
23
+
24
+ Question: Which managers own Neo4j stocks?
25
+ Context:[manager:CTL LLC, manager:JANE STREET GROUP LLC]
26
+ Helpful Answer: CTL LLC, JANE STREET GROUP LLC owns Neo4j stocks.
27
+
28
+ Follow this example when generating answers.
29
+ If the provided information is empty, say that you don't know the answer.
30
+ Information:
31
+ {context}
32
+
33
+ Question: {question}
34
+ Helpful Answer:`,
35
+ inputVariables: ["context", "question"]
36
+ });
37
+ //#endregion
38
+ export { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT };
39
+
40
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","names":[],"sources":["../../../src/chains/graph_qa/prompts.ts"],"sourcesContent":["import { PromptTemplate } from \"@langchain/core/prompts\";\n\nconst CYPHER_GENERATION_TEMPLATE = `Task:Generate Cypher statement to query a graph database.\nInstructions:\nUse only the provided relationship types and properties in the schema.\nDo not use any other relationship types or properties that are not provided.\nSchema:\n{schema}\nNote: Do not include any explanations or apologies in your responses.\nDo not respond to any questions that might ask anything else than for you to construct a Cypher statement.\nDo not include any text except the generated Cypher statement.\n\nThe question is:\n{question}`;\nexport const CYPHER_GENERATION_PROMPT = /* #__PURE__ */ new PromptTemplate({\n template: CYPHER_GENERATION_TEMPLATE,\n inputVariables: [\"schema\", \"question\"],\n});\n\nconst CYPHER_QA_TEMPLATE = `You are an assistant that helps to form nice and human understandable answers.\nThe information part contains the provided information that you must use to construct an answer.\nThe provided information is authoritative, you must never doubt it or try to use your internal knowledge to correct it.\nMake the answer sound as a response to the question. Do not mention that you based the result on the given information.\nHere is an example:\n\nQuestion: Which managers own Neo4j stocks?\nContext:[manager:CTL LLC, manager:JANE STREET GROUP LLC]\nHelpful Answer: CTL LLC, JANE STREET GROUP LLC owns Neo4j stocks.\n\nFollow this example when generating answers.\nIf the provided information is empty, say that you don't know the answer.\nInformation:\n{context}\n\nQuestion: {question}\nHelpful Answer:`;\nexport const CYPHER_QA_PROMPT = /* #__PURE__ */ new PromptTemplate({\n template: CYPHER_QA_TEMPLATE,\n inputVariables: [\"context\", \"question\"],\n});\n"],"mappings":";AAcA,MAAa,2CAA2C,IAAI,eAAe;CACzE,UAbiC;;;;;;;;;;;;CAcjC,gBAAgB,CAAC,UAAU,WAAW;CACvC,CAAC;AAmBF,MAAa,mCAAmC,IAAI,eAAe;CACjE,UAlByB;;;;;;;;;;;;;;;;;CAmBzB,gBAAgB,CAAC,WAAW,WAAW;CACxC,CAAC"}
@@ -0,0 +1,63 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ let _langchain_core_load_serializable = require("@langchain/core/load/serializable");
3
+ //#region src/graphs/document.ts
4
+ var Node = class extends _langchain_core_load_serializable.Serializable {
5
+ id;
6
+ type;
7
+ properties;
8
+ lc_namespace = [
9
+ "langchain",
10
+ "graph",
11
+ "document_node"
12
+ ];
13
+ constructor({ id, type = "Node", properties = {} }) {
14
+ super();
15
+ this.id = id;
16
+ this.type = type;
17
+ this.properties = properties;
18
+ }
19
+ };
20
+ var Relationship = class extends _langchain_core_load_serializable.Serializable {
21
+ source;
22
+ target;
23
+ type;
24
+ properties;
25
+ lc_namespace = [
26
+ "langchain",
27
+ "graph",
28
+ "document_relationship"
29
+ ];
30
+ constructor({ source, target, type, properties = {} }) {
31
+ super();
32
+ this.source = source;
33
+ this.target = target;
34
+ this.type = type;
35
+ this.properties = properties;
36
+ }
37
+ };
38
+ var GraphDocument = class extends _langchain_core_load_serializable.Serializable {
39
+ nodes;
40
+ relationships;
41
+ source;
42
+ lc_namespace = [
43
+ "langchain",
44
+ "graph",
45
+ "graph_document"
46
+ ];
47
+ constructor({ nodes, relationships, source }) {
48
+ super({
49
+ nodes,
50
+ relationships,
51
+ source
52
+ });
53
+ this.nodes = nodes;
54
+ this.relationships = relationships;
55
+ this.source = source;
56
+ }
57
+ };
58
+ //#endregion
59
+ exports.GraphDocument = GraphDocument;
60
+ exports.Node = Node;
61
+ exports.Relationship = Relationship;
62
+
63
+ //# sourceMappingURL=document.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.cjs","names":["Serializable"],"sources":["../../src/graphs/document.ts"],"sourcesContent":["import { Serializable } from \"@langchain/core/load/serializable\";\nimport { Document } from \"@langchain/core/documents\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Any = any;\n\nexport class Node extends Serializable {\n id: string | number;\n\n type: string;\n\n properties: Record<string, Any>;\n\n lc_namespace = [\"langchain\", \"graph\", \"document_node\"];\n\n constructor({\n id,\n type = \"Node\",\n properties = {},\n }: {\n id: string | number;\n type: string;\n properties?: Record<string, Any>;\n }) {\n super();\n this.id = id;\n this.type = type;\n this.properties = properties;\n }\n}\n\nexport class Relationship extends Serializable {\n source: Node;\n\n target: Node;\n\n type: string;\n\n properties: Record<string, Any>;\n\n lc_namespace = [\"langchain\", \"graph\", \"document_relationship\"];\n\n constructor({\n source,\n target,\n type,\n properties = {},\n }: {\n source: Node;\n target: Node;\n type: string;\n properties?: Record<string, Any>;\n }) {\n super();\n this.source = source;\n this.target = target;\n this.type = type;\n this.properties = properties;\n }\n}\n\nexport class GraphDocument extends Serializable {\n nodes: Node[];\n\n relationships: Relationship[];\n\n source: Document;\n\n lc_namespace = [\"langchain\", \"graph\", \"graph_document\"];\n\n constructor({\n nodes,\n relationships,\n source,\n }: {\n nodes: Node[];\n relationships: Relationship[];\n source: Document;\n }) {\n super({\n nodes,\n relationships,\n source,\n });\n this.nodes = nodes;\n this.relationships = relationships;\n this.source = source;\n }\n}\n"],"mappings":";;;AAMA,IAAa,OAAb,cAA0BA,kCAAAA,aAAa;CACrC;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;EAAgB;CAEtD,YAAY,EACV,IACA,OAAO,QACP,aAAa,EAAE,IAKd;AACD,SAAO;AACP,OAAK,KAAK;AACV,OAAK,OAAO;AACZ,OAAK,aAAa;;;AAItB,IAAa,eAAb,cAAkCA,kCAAAA,aAAa;CAC7C;CAEA;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;EAAwB;CAE9D,YAAY,EACV,QACA,QACA,MACA,aAAa,EAAE,IAMd;AACD,SAAO;AACP,OAAK,SAAS;AACd,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,aAAa;;;AAItB,IAAa,gBAAb,cAAmCA,kCAAAA,aAAa;CAC9C;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;EAAiB;CAEvD,YAAY,EACV,OACA,eACA,UAKC;AACD,QAAM;GACJ;GACA;GACA;GACD,CAAC;AACF,OAAK,QAAQ;AACb,OAAK,gBAAgB;AACrB,OAAK,SAAS"}
@@ -0,0 +1,56 @@
1
+ import { Serializable } from "@langchain/core/load/serializable";
2
+ import { Document } from "@langchain/core/documents";
3
+
4
+ //#region src/graphs/document.d.ts
5
+ type Any = any;
6
+ declare class Node extends Serializable {
7
+ id: string | number;
8
+ type: string;
9
+ properties: Record<string, Any>;
10
+ lc_namespace: string[];
11
+ constructor({
12
+ id,
13
+ type,
14
+ properties
15
+ }: {
16
+ id: string | number;
17
+ type: string;
18
+ properties?: Record<string, Any>;
19
+ });
20
+ }
21
+ declare class Relationship extends Serializable {
22
+ source: Node;
23
+ target: Node;
24
+ type: string;
25
+ properties: Record<string, Any>;
26
+ lc_namespace: string[];
27
+ constructor({
28
+ source,
29
+ target,
30
+ type,
31
+ properties
32
+ }: {
33
+ source: Node;
34
+ target: Node;
35
+ type: string;
36
+ properties?: Record<string, Any>;
37
+ });
38
+ }
39
+ declare class GraphDocument extends Serializable {
40
+ nodes: Node[];
41
+ relationships: Relationship[];
42
+ source: Document;
43
+ lc_namespace: string[];
44
+ constructor({
45
+ nodes,
46
+ relationships,
47
+ source
48
+ }: {
49
+ nodes: Node[];
50
+ relationships: Relationship[];
51
+ source: Document;
52
+ });
53
+ }
54
+ //#endregion
55
+ export { GraphDocument, Node, Relationship };
56
+ //# sourceMappingURL=document.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.cts","names":[],"sources":["../../src/graphs/document.ts"],"mappings":";;;;KAIK,GAAA;AAAA,cAEQ,IAAA,SAAa,YAAA;EACxB,EAAA;EAEA,IAAA;EAEA,UAAA,EAAY,MAAA,SAAe,GAAA;EAE3B,YAAA;EAEA,WAAA,CAAA;IACE,EAAA;IACA,IAAA;IACA;EAAA;IAEA,EAAA;IACA,IAAA;IACA,UAAA,GAAa,MAAA,SAAe,GAAA;EAAA;AAAA;AAAA,cASnB,YAAA,SAAqB,YAAA;EAChC,MAAA,EAAQ,IAAA;EAER,MAAA,EAAQ,IAAA;EAER,IAAA;EAEA,UAAA,EAAY,MAAA,SAAe,GAAA;EAE3B,YAAA;EAEA,WAAA,CAAA;IACE,MAAA;IACA,MAAA;IACA,IAAA;IACA;EAAA;IAEA,MAAA,EAAQ,IAAA;IACR,MAAA,EAAQ,IAAA;IACR,IAAA;IACA,UAAA,GAAa,MAAA,SAAe,GAAA;EAAA;AAAA;AAAA,cAUnB,aAAA,SAAsB,YAAA;EACjC,KAAA,EAAO,IAAA;EAEP,aAAA,EAAe,YAAA;EAEf,MAAA,EAAQ,QAAA;EAER,YAAA;EAEA,WAAA,CAAA;IACE,KAAA;IACA,aAAA;IACA;EAAA;IAEA,KAAA,EAAO,IAAA;IACP,aAAA,EAAe,YAAA;IACf,MAAA,EAAQ,QAAA;EAAA;AAAA"}
@@ -0,0 +1,56 @@
1
+ import { Serializable } from "@langchain/core/load/serializable";
2
+ import { Document } from "@langchain/core/documents";
3
+
4
+ //#region src/graphs/document.d.ts
5
+ type Any = any;
6
+ declare class Node extends Serializable {
7
+ id: string | number;
8
+ type: string;
9
+ properties: Record<string, Any>;
10
+ lc_namespace: string[];
11
+ constructor({
12
+ id,
13
+ type,
14
+ properties
15
+ }: {
16
+ id: string | number;
17
+ type: string;
18
+ properties?: Record<string, Any>;
19
+ });
20
+ }
21
+ declare class Relationship extends Serializable {
22
+ source: Node;
23
+ target: Node;
24
+ type: string;
25
+ properties: Record<string, Any>;
26
+ lc_namespace: string[];
27
+ constructor({
28
+ source,
29
+ target,
30
+ type,
31
+ properties
32
+ }: {
33
+ source: Node;
34
+ target: Node;
35
+ type: string;
36
+ properties?: Record<string, Any>;
37
+ });
38
+ }
39
+ declare class GraphDocument extends Serializable {
40
+ nodes: Node[];
41
+ relationships: Relationship[];
42
+ source: Document;
43
+ lc_namespace: string[];
44
+ constructor({
45
+ nodes,
46
+ relationships,
47
+ source
48
+ }: {
49
+ nodes: Node[];
50
+ relationships: Relationship[];
51
+ source: Document;
52
+ });
53
+ }
54
+ //#endregion
55
+ export { GraphDocument, Node, Relationship };
56
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","names":[],"sources":["../../src/graphs/document.ts"],"mappings":";;;;KAIK,GAAA;AAAA,cAEQ,IAAA,SAAa,YAAA;EACxB,EAAA;EAEA,IAAA;EAEA,UAAA,EAAY,MAAA,SAAe,GAAA;EAE3B,YAAA;EAEA,WAAA,CAAA;IACE,EAAA;IACA,IAAA;IACA;EAAA;IAEA,EAAA;IACA,IAAA;IACA,UAAA,GAAa,MAAA,SAAe,GAAA;EAAA;AAAA;AAAA,cASnB,YAAA,SAAqB,YAAA;EAChC,MAAA,EAAQ,IAAA;EAER,MAAA,EAAQ,IAAA;EAER,IAAA;EAEA,UAAA,EAAY,MAAA,SAAe,GAAA;EAE3B,YAAA;EAEA,WAAA,CAAA;IACE,MAAA;IACA,MAAA;IACA,IAAA;IACA;EAAA;IAEA,MAAA,EAAQ,IAAA;IACR,MAAA,EAAQ,IAAA;IACR,IAAA;IACA,UAAA,GAAa,MAAA,SAAe,GAAA;EAAA;AAAA;AAAA,cAUnB,aAAA,SAAsB,YAAA;EACjC,KAAA,EAAO,IAAA;EAEP,aAAA,EAAe,YAAA;EAEf,MAAA,EAAQ,QAAA;EAER,YAAA;EAEA,WAAA,CAAA;IACE,KAAA;IACA,aAAA;IACA;EAAA;IAEA,KAAA,EAAO,IAAA;IACP,aAAA,EAAe,YAAA;IACf,MAAA,EAAQ,QAAA;EAAA;AAAA"}
@@ -0,0 +1,60 @@
1
+ import { Serializable } from "@langchain/core/load/serializable";
2
+ //#region src/graphs/document.ts
3
+ var Node = class extends Serializable {
4
+ id;
5
+ type;
6
+ properties;
7
+ lc_namespace = [
8
+ "langchain",
9
+ "graph",
10
+ "document_node"
11
+ ];
12
+ constructor({ id, type = "Node", properties = {} }) {
13
+ super();
14
+ this.id = id;
15
+ this.type = type;
16
+ this.properties = properties;
17
+ }
18
+ };
19
+ var Relationship = class extends Serializable {
20
+ source;
21
+ target;
22
+ type;
23
+ properties;
24
+ lc_namespace = [
25
+ "langchain",
26
+ "graph",
27
+ "document_relationship"
28
+ ];
29
+ constructor({ source, target, type, properties = {} }) {
30
+ super();
31
+ this.source = source;
32
+ this.target = target;
33
+ this.type = type;
34
+ this.properties = properties;
35
+ }
36
+ };
37
+ var GraphDocument = class extends Serializable {
38
+ nodes;
39
+ relationships;
40
+ source;
41
+ lc_namespace = [
42
+ "langchain",
43
+ "graph",
44
+ "graph_document"
45
+ ];
46
+ constructor({ nodes, relationships, source }) {
47
+ super({
48
+ nodes,
49
+ relationships,
50
+ source
51
+ });
52
+ this.nodes = nodes;
53
+ this.relationships = relationships;
54
+ this.source = source;
55
+ }
56
+ };
57
+ //#endregion
58
+ export { GraphDocument, Node, Relationship };
59
+
60
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.js","names":[],"sources":["../../src/graphs/document.ts"],"sourcesContent":["import { Serializable } from \"@langchain/core/load/serializable\";\nimport { Document } from \"@langchain/core/documents\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Any = any;\n\nexport class Node extends Serializable {\n id: string | number;\n\n type: string;\n\n properties: Record<string, Any>;\n\n lc_namespace = [\"langchain\", \"graph\", \"document_node\"];\n\n constructor({\n id,\n type = \"Node\",\n properties = {},\n }: {\n id: string | number;\n type: string;\n properties?: Record<string, Any>;\n }) {\n super();\n this.id = id;\n this.type = type;\n this.properties = properties;\n }\n}\n\nexport class Relationship extends Serializable {\n source: Node;\n\n target: Node;\n\n type: string;\n\n properties: Record<string, Any>;\n\n lc_namespace = [\"langchain\", \"graph\", \"document_relationship\"];\n\n constructor({\n source,\n target,\n type,\n properties = {},\n }: {\n source: Node;\n target: Node;\n type: string;\n properties?: Record<string, Any>;\n }) {\n super();\n this.source = source;\n this.target = target;\n this.type = type;\n this.properties = properties;\n }\n}\n\nexport class GraphDocument extends Serializable {\n nodes: Node[];\n\n relationships: Relationship[];\n\n source: Document;\n\n lc_namespace = [\"langchain\", \"graph\", \"graph_document\"];\n\n constructor({\n nodes,\n relationships,\n source,\n }: {\n nodes: Node[];\n relationships: Relationship[];\n source: Document;\n }) {\n super({\n nodes,\n relationships,\n source,\n });\n this.nodes = nodes;\n this.relationships = relationships;\n this.source = source;\n }\n}\n"],"mappings":";;AAMA,IAAa,OAAb,cAA0B,aAAa;CACrC;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;EAAgB;CAEtD,YAAY,EACV,IACA,OAAO,QACP,aAAa,EAAE,IAKd;AACD,SAAO;AACP,OAAK,KAAK;AACV,OAAK,OAAO;AACZ,OAAK,aAAa;;;AAItB,IAAa,eAAb,cAAkC,aAAa;CAC7C;CAEA;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;EAAwB;CAE9D,YAAY,EACV,QACA,QACA,MACA,aAAa,EAAE,IAMd;AACD,SAAO;AACP,OAAK,SAAS;AACd,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,aAAa;;;AAItB,IAAa,gBAAb,cAAmC,aAAa;CAC9C;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;EAAiB;CAEvD,YAAY,EACV,OACA,eACA,UAKC;AACD,QAAM;GACJ;GACA;GACA;GACD,CAAC;AACF,OAAK,QAAQ;AACb,OAAK,gBAAgB;AACrB,OAAK,SAAS"}
@@ -0,0 +1,3 @@
1
+ require("./neo4j_graph.cjs");
2
+ require("./memgraph_graph.cjs");
3
+ require("./document.cjs");
@@ -0,0 +1,3 @@
1
+ import { GraphDocument, Node, Relationship } from "./document.js";
2
+ import { AddGraphDocumentsConfig, BASE_ENTITY_LABEL, Neo4jGraph, Neo4jGraphConfig, NodeType, PathType, RelType, StructuredSchema, formatSchema } from "./neo4j_graph.js";
3
+ import { MemgraphGraph, MemgraphGraphConfig } from "./memgraph_graph.js";
@@ -0,0 +1,4 @@
1
+ import "./neo4j_graph.js";
2
+ import "./memgraph_graph.js";
3
+ import "./document.js";
4
+ export {};
@@ -0,0 +1,74 @@
1
+ const require_neo4j_graph = require("./neo4j_graph.cjs");
2
+ //#region src/graphs/memgraph_graph.ts
3
+ const rawSchemaQuery = `
4
+ CALL llm_util.schema("raw")
5
+ YIELD *
6
+ RETURN *
7
+ `;
8
+ /**
9
+ * @security *Security note*: Make sure that the database connection uses credentials
10
+ * that are narrowly-scoped to only include necessary permissions.
11
+ * Failure to do so may result in data corruption or loss, since the calling
12
+ * code may attempt commands that would result in deletion, mutation
13
+ * of data if appropriately prompted or reading sensitive data if such
14
+ * data is present in the database.
15
+ * The best way to guard against such negative outcomes is to (as appropriate)
16
+ * limit the permissions granted to the credentials used with this tool.
17
+ * For example, creating read only users for the database is a good way to
18
+ * ensure that the calling code cannot mutate or delete data.
19
+ *
20
+ * @link See https://js.langchain.com/docs/security for more information.
21
+ */
22
+ var MemgraphGraph = class MemgraphGraph extends require_neo4j_graph.Neo4jGraph {
23
+ constructor({ url, username, password, database = "memgraph" }) {
24
+ super({
25
+ url,
26
+ username,
27
+ password,
28
+ database
29
+ });
30
+ }
31
+ static async initialize(config) {
32
+ const graph = new MemgraphGraph(config);
33
+ try {
34
+ await graph.verifyConnectivity();
35
+ } catch {
36
+ console.error("Failed to verify connection.");
37
+ }
38
+ try {
39
+ await graph.refreshSchema();
40
+ console.debug("Schema refreshed successfully.");
41
+ } catch (e) {
42
+ const error = e;
43
+ throw new Error(error.message);
44
+ }
45
+ return graph;
46
+ }
47
+ async refreshSchema() {
48
+ const rawSchemaQueryResult = await this.query(rawSchemaQuery);
49
+ if (rawSchemaQueryResult?.[0]?.schema) {
50
+ const rawSchema = rawSchemaQueryResult?.[0]?.schema;
51
+ this.structuredSchema = {
52
+ nodeProps: rawSchema.node_props,
53
+ relProps: rawSchema.rel_props,
54
+ relationships: rawSchema.relationships
55
+ };
56
+ this.schema = [
57
+ "Node properties are the following:",
58
+ Object.entries(rawSchema.node_props).map(([nodeName, properties]) => {
59
+ return `Node name: '${nodeName}', Node properties: ${JSON.stringify(properties)}`;
60
+ }).join("\n"),
61
+ "Relationship properties are the following:",
62
+ Object.entries(rawSchema.rel_props).map(([relationshipName, properties]) => {
63
+ return `Relationship name: '${relationshipName}', Relationship properties: ${JSON.stringify(properties)}`;
64
+ }).join("\n"),
65
+ "The relationships are the following:",
66
+ rawSchema.relationships?.map((el) => `(:${el.start})-[:${el.type}]->(:${el.end})`).join("\n")
67
+ ].join("\n");
68
+ }
69
+ }
70
+ };
71
+ //#endregion
72
+ exports.MemgraphGraph = MemgraphGraph;
73
+
74
+ //# sourceMappingURL=memgraph_graph.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memgraph_graph.cjs","names":["Neo4jGraph"],"sources":["../../src/graphs/memgraph_graph.ts"],"sourcesContent":["import { Neo4jGraph } from \"./neo4j_graph.js\";\n\nexport interface MemgraphGraphConfig {\n url: string;\n username: string;\n password: string;\n database?: string;\n}\n\nconst rawSchemaQuery = `\nCALL llm_util.schema(\"raw\")\nYIELD *\nRETURN *\n`;\n\n/**\n * @security *Security note*: Make sure that the database connection uses credentials\n * that are narrowly-scoped to only include necessary permissions.\n * Failure to do so may result in data corruption or loss, since the calling\n * code may attempt commands that would result in deletion, mutation\n * of data if appropriately prompted or reading sensitive data if such\n * data is present in the database.\n * The best way to guard against such negative outcomes is to (as appropriate)\n * limit the permissions granted to the credentials used with this tool.\n * For example, creating read only users for the database is a good way to\n * ensure that the calling code cannot mutate or delete data.\n *\n * @link See https://js.langchain.com/docs/security for more information.\n */\nexport class MemgraphGraph extends Neo4jGraph {\n constructor({\n url,\n username,\n password,\n database = \"memgraph\",\n }: MemgraphGraphConfig) {\n super({ url, username, password, database });\n }\n\n static async initialize(config: MemgraphGraphConfig): Promise<MemgraphGraph> {\n const graph = new MemgraphGraph(config);\n\n try {\n await graph.verifyConnectivity();\n } catch {\n console.error(\"Failed to verify connection.\");\n }\n\n try {\n await graph.refreshSchema();\n console.debug(\"Schema refreshed successfully.\");\n } catch (e) {\n const error = e as Error;\n throw new Error(error.message);\n }\n\n return graph;\n }\n\n async refreshSchema() {\n const rawSchemaQueryResult = await this.query(rawSchemaQuery);\n if (rawSchemaQueryResult?.[0]?.schema) {\n const rawSchema = rawSchemaQueryResult?.[0]?.schema;\n\n this.structuredSchema = {\n nodeProps: rawSchema.node_props,\n relProps: rawSchema.rel_props,\n relationships: rawSchema.relationships,\n };\n\n const formattedNodeProps = Object.entries(rawSchema.node_props)\n .map(([nodeName, properties]) => {\n const propertiesStr = JSON.stringify(properties);\n return `Node name: '${nodeName}', Node properties: ${propertiesStr}`;\n })\n .join(\"\\n\");\n\n const formattedRelProps = Object.entries(rawSchema.rel_props)\n .map(([relationshipName, properties]) => {\n const propertiesStr = JSON.stringify(properties);\n return `Relationship name: '${relationshipName}', Relationship properties: ${propertiesStr}`;\n })\n .join(\"\\n\");\n\n const formattedRels = rawSchema.relationships\n ?.map(\n (el: { end: string; start: string; type: string }) =>\n `(:${el.start})-[:${el.type}]->(:${el.end})`\n )\n .join(\"\\n\");\n\n this.schema = [\n \"Node properties are the following:\",\n formattedNodeProps,\n \"Relationship properties are the following:\",\n formattedRelProps,\n \"The relationships are the following:\",\n formattedRels,\n ].join(\"\\n\");\n }\n }\n}\n"],"mappings":";;AASA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;AAoBvB,IAAa,gBAAb,MAAa,sBAAsBA,oBAAAA,WAAW;CAC5C,YAAY,EACV,KACA,UACA,UACA,WAAW,cACW;AACtB,QAAM;GAAE;GAAK;GAAU;GAAU;GAAU,CAAC;;CAG9C,aAAa,WAAW,QAAqD;EAC3E,MAAM,QAAQ,IAAI,cAAc,OAAO;AAEvC,MAAI;AACF,SAAM,MAAM,oBAAoB;UAC1B;AACN,WAAQ,MAAM,+BAA+B;;AAG/C,MAAI;AACF,SAAM,MAAM,eAAe;AAC3B,WAAQ,MAAM,iCAAiC;WACxC,GAAG;GACV,MAAM,QAAQ;AACd,SAAM,IAAI,MAAM,MAAM,QAAQ;;AAGhC,SAAO;;CAGT,MAAM,gBAAgB;EACpB,MAAM,uBAAuB,MAAM,KAAK,MAAM,eAAe;AAC7D,MAAI,uBAAuB,IAAI,QAAQ;GACrC,MAAM,YAAY,uBAAuB,IAAI;AAE7C,QAAK,mBAAmB;IACtB,WAAW,UAAU;IACrB,UAAU,UAAU;IACpB,eAAe,UAAU;IAC1B;AAuBD,QAAK,SAAS;IACZ;IAtByB,OAAO,QAAQ,UAAU,WAAW,CAC5D,KAAK,CAAC,UAAU,gBAAgB;AAE/B,YAAO,eAAe,SAAS,sBADT,KAAK,UAAU,WAAW;MAEhD,CACD,KAAK,KAAK;IAmBX;IAjBwB,OAAO,QAAQ,UAAU,UAAU,CAC1D,KAAK,CAAC,kBAAkB,gBAAgB;AAEvC,YAAO,uBAAuB,iBAAiB,8BADzB,KAAK,UAAU,WAAW;MAEhD,CACD,KAAK,KAAK;IAcX;IAZoB,UAAU,eAC5B,KACC,OACC,KAAK,GAAG,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,GAC7C,CACA,KAAK,KAAK;IASZ,CAAC,KAAK,KAAK"}