@langchain/neo4j 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chains/graph_qa/cypher.cjs +5 -5
- package/dist/chains/graph_qa/cypher.cjs.map +1 -1
- package/dist/chains/graph_qa/cypher.d.cts +0 -1
- package/dist/chains/graph_qa/cypher.d.cts.map +1 -1
- package/dist/chains/graph_qa/cypher.d.ts +0 -1
- package/dist/chains/graph_qa/cypher.d.ts.map +1 -1
- package/dist/chains/graph_qa/cypher.js +5 -4
- package/dist/chains/graph_qa/cypher.js.map +1 -1
- package/dist/chains/graph_qa/index.cjs +6 -2
- package/dist/chains/graph_qa/index.d.cts +2 -1
- package/dist/chains/graph_qa/index.d.ts +2 -1
- package/dist/chains/graph_qa/index.js +3 -3
- package/dist/chains/graph_qa/prompts.cjs +2 -3
- package/dist/chains/graph_qa/prompts.cjs.map +1 -1
- package/dist/chains/graph_qa/prompts.d.cts +0 -1
- package/dist/chains/graph_qa/prompts.d.cts.map +1 -1
- package/dist/chains/graph_qa/prompts.d.ts +0 -1
- package/dist/chains/graph_qa/prompts.d.ts.map +1 -1
- package/dist/chains/graph_qa/prompts.js +2 -2
- package/dist/chains/graph_qa/prompts.js.map +1 -1
- package/dist/graphs/document.cjs +0 -1
- package/dist/graphs/document.cjs.map +1 -1
- package/dist/graphs/document.d.cts +3 -17
- package/dist/graphs/document.d.cts.map +1 -1
- package/dist/graphs/document.d.ts +3 -17
- package/dist/graphs/document.d.ts.map +1 -1
- package/dist/graphs/document.js.map +1 -1
- package/dist/graphs/index.cjs +10 -3
- package/dist/graphs/index.d.cts +2 -1
- package/dist/graphs/index.d.ts +2 -1
- package/dist/graphs/index.js +4 -4
- package/dist/graphs/memgraph_graph.cjs.map +1 -1
- package/dist/graphs/memgraph_graph.d.cts +1 -7
- package/dist/graphs/memgraph_graph.d.cts.map +1 -1
- package/dist/graphs/memgraph_graph.d.ts +1 -7
- package/dist/graphs/memgraph_graph.d.ts.map +1 -1
- package/dist/graphs/memgraph_graph.js.map +1 -1
- package/dist/graphs/neo4j_graph.cjs.map +1 -1
- package/dist/graphs/neo4j_graph.d.cts +1 -9
- package/dist/graphs/neo4j_graph.d.cts.map +1 -1
- package/dist/graphs/neo4j_graph.d.ts +1 -9
- package/dist/graphs/neo4j_graph.d.ts.map +1 -1
- package/dist/graphs/neo4j_graph.js.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/stores/message/index.cjs +2 -1
- package/dist/stores/message/index.d.cts +2 -1
- package/dist/stores/message/index.d.ts +2 -1
- package/dist/stores/message/index.js +2 -2
- package/dist/stores/message/neo4j.cjs.map +1 -1
- package/dist/stores/message/neo4j.d.cts +1 -10
- package/dist/stores/message/neo4j.d.cts.map +1 -1
- package/dist/stores/message/neo4j.d.ts +1 -10
- package/dist/stores/message/neo4j.d.ts.map +1 -1
- package/dist/stores/message/neo4j.js.map +1 -1
- package/dist/vectorstores/index.cjs +5 -1
- package/dist/vectorstores/index.d.cts +2 -1
- package/dist/vectorstores/index.d.ts +2 -1
- package/dist/vectorstores/index.js +2 -2
- package/dist/vectorstores/neo4j_vector.cjs +4 -4
- package/dist/vectorstores/neo4j_vector.cjs.map +1 -1
- package/dist/vectorstores/neo4j_vector.d.cts +1 -7
- package/dist/vectorstores/neo4j_vector.d.cts.map +1 -1
- package/dist/vectorstores/neo4j_vector.d.ts +1 -7
- package/dist/vectorstores/neo4j_vector.d.ts.map +1 -1
- package/dist/vectorstores/neo4j_vector.js +4 -4
- package/dist/vectorstores/neo4j_vector.js.map +1 -1
- package/package.json +9 -9
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_prompts = require("./prompts.cjs");
|
|
3
2
|
let _langchain_classic_chains = require("@langchain/classic/chains");
|
|
4
3
|
//#region src/chains/graph_qa/cypher.ts
|
|
@@ -66,11 +65,12 @@ var GraphCypherQAChain = class GraphCypherQAChain extends _langchain_classic_cha
|
|
|
66
65
|
llm: qaLLM || llm,
|
|
67
66
|
prompt: qaPrompt
|
|
68
67
|
});
|
|
68
|
+
const cypherGenerationChain = new _langchain_classic_chains.LLMChain({
|
|
69
|
+
llm: cypherLLM || llm,
|
|
70
|
+
prompt: cypherPrompt
|
|
71
|
+
});
|
|
69
72
|
return new GraphCypherQAChain({
|
|
70
|
-
cypherGenerationChain
|
|
71
|
-
llm: cypherLLM || llm,
|
|
72
|
-
prompt: cypherPrompt
|
|
73
|
-
}),
|
|
73
|
+
cypherGenerationChain,
|
|
74
74
|
qaChain,
|
|
75
75
|
graph,
|
|
76
76
|
returnIntermediateSteps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cypher.cjs","names":["BaseChain","CYPHER_QA_PROMPT","CYPHER_GENERATION_PROMPT","LLMChain"],"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":"
|
|
1
|
+
{"version":3,"file":"cypher.cjs","names":["BaseChain","CYPHER_QA_PROMPT","CYPHER_GENERATION_PROMPT","LLMChain"],"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,2BAA2BA,0BAAAA,UAAU;CAChD;CAEA;CAEA;CAEA,WAAmB;CAEnB,YAAoB;CAEpB,OAAe;CAEf,eAAuB;CAEvB,0BAAkC;CAElC,YAAY,OAAgC;EAC1C,MAAM,KAAK;EACX,MAAM,EACJ,OACA,uBACA,SACA,UACA,WACA,MACA,yBACA,iBACE;EAEJ,KAAK,QAAQ;EACb,KAAK,wBAAwB;EAC7B,KAAK,UAAU;EAEf,IAAI,UACF,KAAK,WAAW;EAElB,IAAI,WACF,KAAK,YAAY;EAEnB,IAAI,MACF,KAAK,OAAO;EAEd,IAAI,yBACF,KAAK,0BAA0B;EAEjC,IAAI,cACF,KAAK,eAAe;CAExB;CAEA,aAAa;EACX,OAAO;CACT;CAEA,IAAI,YAAsB;EACxB,OAAO,CAAC,KAAK,QAAQ;CACvB;CAEA,IAAI,aAAuB;EACzB,OAAO,CAAC,KAAK,SAAS;CACxB;CAEA,OAAO,QAAQ,OAAyC;EACtD,MAAM,EACJ,OACA,WAAWC,gBAAAA,kBACX,eAAeC,gBAAAA,0BACf,KACA,WACA,OACA,0BAA0B,OAC1B,eAAe,UACb;EAEJ,IAAI,CAAC,aAAa,CAAC,KACjB,MAAM,IAAI,MACR,yDACF;EAGF,IAAI,CAAC,SAAS,CAAC,KACb,MAAM,IAAI,MAAM,qDAAqD;EAGvE,IAAI,aAAa,SAAS,KACxB,MAAM,IAAI,MACR,iGACF;EAGF,MAAM,UAAU,IAAIC,0BAAAA,SAAS;GAC3B,KAAM,SAAS;GACf,QAAQ;EACV,CAAC;EAED,MAAM,wBAAwB,IAAIA,0BAAAA,SAAS;GACzC,KAAM,aAAa;GACnB,QAAQ;EACV,CAAC;EAED,OAAO,IAAI,mBAAmB;GAC5B;GACA;GACA;GACA;GACA;EACF,CAAC;CACH;CAEA,cAAsB,MAAsB;EAE1C,MAAM,UAAU,KAAK,MAAM,cAAO;EAClC,OAAO,UAAU,QAAQ,KAAK;CAChC;CAEA,MAAM,MACJ,QACA,YACsB;EACtB,MAAM,YAAY,YAAY,SAAS;EACvC,MAAM,WAAW,OAAO,KAAK;EAE7B,MAAM,oBAAoB,CAAC;EAE3B,MAAM,kBAAkB,MAAM,KAAK,sBAAsB,KACvD;GAAE;GAAU,QAAQ,KAAK,MAAM,UAAU;EAAE,GAC3C,SACF;EAEA,MAAM,kBAAkB,KAAK,cAAc,gBAAgB,IAAI;EAE/D,MAAM,YAAY,WAAW,qBAAqB;EAClD,MAAM,YAAY,WAAW,GAAG,gBAAgB,SAAS;EAEzD,kBAAkB,KAAK,EAAE,OAAO,gBAAgB,CAAC;EAEjD,IAAI;EACJ,MAAM,UAAU,MAAM,KAAK,MAAM,MAAM,iBAAiB,EACtD,MAAM,KAAK,KACb,CAAC;EAED,IAAI,KAAK,cACP,cAAc,GAAG,KAAK,YAAY,QAAQ;OACrC;GACL,MAAM,YAAY,WAAW,iBAAiB;GAC9C,MAAM,YAAY,WAAW,GAAG,QAAQ,SAAS;GAEjD,kBAAkB,KAAK,EAAE,QAAQ,CAAC;GAElC,MAAM,SAAS,MAAM,KAAK,QAAQ,KAChC;IAAE;IAAU,SAAS,KAAK,UAAU,OAAO;GAAE,GAC7C,SACF;GAEA,cAAc,GACX,KAAK,YAAY,OAAO,KAAK,QAAQ,WACxC;EACF;EAEA,IAAI,KAAK,yBACP,YAAY,0BAA0B;EAGxC,OAAO;CACT;AACF"}
|
|
@@ -4,7 +4,6 @@ import { ChainValues } from "@langchain/core/utils/types";
|
|
|
4
4
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
5
5
|
import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
|
|
6
6
|
import { BaseChain, ChainInputs, LLMChain } from "@langchain/classic/chains";
|
|
7
|
-
|
|
8
7
|
//#region src/chains/graph_qa/cypher.d.ts
|
|
9
8
|
declare const INTERMEDIATE_STEPS_KEY = "intermediateSteps";
|
|
10
9
|
interface GraphCypherQAChainInput extends ChainInputs {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cypher.d.cts","names":[],"sources":["../../../src/chains/graph_qa/cypher.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cypher.d.cts","names":[],"sources":["../../../src/chains/graph_qa/cypher.ts"],"mappings":";;;;;;;cAQa;UAEI,gCAAgC;EAC/C,OAAO;EACP,uBAAuB;EACvB,SAAS;EACT;EACA;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP,MAAM;EACN,YAAY;EACZ,QAAQ;EACR,WAAW;EACX,eAAe;EACf;EACA;;;;;;;;;;;;;;;;;;;;;;;;;;cA2BW,2BAA2B;UAC9B;UAEA;UAEA;UAEA;UAEA;UAEA;UAEA;UAEA;EAER,YAAY,OAAO;EAkCnB;MAII;MAIA;SAIG,QAAQ,OAAO,eAAe;UA+C7B;EAMF,MACJ,QAAQ,aACR,aAAa,6BACZ,QAAQ"}
|
|
@@ -4,7 +4,6 @@ import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
|
4
4
|
import { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
|
|
5
5
|
import { ChainValues } from "@langchain/core/utils/types";
|
|
6
6
|
import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
|
|
7
|
-
|
|
8
7
|
//#region src/chains/graph_qa/cypher.d.ts
|
|
9
8
|
declare const INTERMEDIATE_STEPS_KEY = "intermediateSteps";
|
|
10
9
|
interface GraphCypherQAChainInput extends ChainInputs {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cypher.d.ts","names":[],"sources":["../../../src/chains/graph_qa/cypher.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cypher.d.ts","names":[],"sources":["../../../src/chains/graph_qa/cypher.ts"],"mappings":";;;;;;;cAQa;UAEI,gCAAgC;EAC/C,OAAO;EACP,uBAAuB;EACvB,SAAS;EACT;EACA;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP,MAAM;EACN,YAAY;EACZ,QAAQ;EACR,WAAW;EACX,eAAe;EACf;EACA;;;;;;;;;;;;;;;;;;;;;;;;;;cA2BW,2BAA2B;UAC9B;UAEA;UAEA;UAEA;UAEA;UAEA;UAEA;UAEA;EAER,YAAY,OAAO;EAkCnB;MAII;MAIA;SAIG,QAAQ,OAAO,eAAe;UA+C7B;EAMF,MACJ,QAAQ,aACR,aAAa,6BACZ,QAAQ"}
|
|
@@ -65,11 +65,12 @@ var GraphCypherQAChain = class GraphCypherQAChain extends BaseChain {
|
|
|
65
65
|
llm: qaLLM || llm,
|
|
66
66
|
prompt: qaPrompt
|
|
67
67
|
});
|
|
68
|
+
const cypherGenerationChain = new LLMChain({
|
|
69
|
+
llm: cypherLLM || llm,
|
|
70
|
+
prompt: cypherPrompt
|
|
71
|
+
});
|
|
68
72
|
return new GraphCypherQAChain({
|
|
69
|
-
cypherGenerationChain
|
|
70
|
-
llm: cypherLLM || llm,
|
|
71
|
-
prompt: cypherPrompt
|
|
72
|
-
}),
|
|
73
|
+
cypherGenerationChain,
|
|
73
74
|
qaChain,
|
|
74
75
|
graph,
|
|
75
76
|
returnIntermediateSteps,
|
|
@@ -1 +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;
|
|
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;EAC1C,MAAM,KAAK;EACX,MAAM,EACJ,OACA,uBACA,SACA,UACA,WACA,MACA,yBACA,iBACE;EAEJ,KAAK,QAAQ;EACb,KAAK,wBAAwB;EAC7B,KAAK,UAAU;EAEf,IAAI,UACF,KAAK,WAAW;EAElB,IAAI,WACF,KAAK,YAAY;EAEnB,IAAI,MACF,KAAK,OAAO;EAEd,IAAI,yBACF,KAAK,0BAA0B;EAEjC,IAAI,cACF,KAAK,eAAe;CAExB;CAEA,aAAa;EACX,OAAO;CACT;CAEA,IAAI,YAAsB;EACxB,OAAO,CAAC,KAAK,QAAQ;CACvB;CAEA,IAAI,aAAuB;EACzB,OAAO,CAAC,KAAK,SAAS;CACxB;CAEA,OAAO,QAAQ,OAAyC;EACtD,MAAM,EACJ,OACA,WAAW,kBACX,eAAe,0BACf,KACA,WACA,OACA,0BAA0B,OAC1B,eAAe,UACb;EAEJ,IAAI,CAAC,aAAa,CAAC,KACjB,MAAM,IAAI,MACR,yDACF;EAGF,IAAI,CAAC,SAAS,CAAC,KACb,MAAM,IAAI,MAAM,qDAAqD;EAGvE,IAAI,aAAa,SAAS,KACxB,MAAM,IAAI,MACR,iGACF;EAGF,MAAM,UAAU,IAAI,SAAS;GAC3B,KAAM,SAAS;GACf,QAAQ;EACV,CAAC;EAED,MAAM,wBAAwB,IAAI,SAAS;GACzC,KAAM,aAAa;GACnB,QAAQ;EACV,CAAC;EAED,OAAO,IAAI,mBAAmB;GAC5B;GACA;GACA;GACA;GACA;EACF,CAAC;CACH;CAEA,cAAsB,MAAsB;EAE1C,MAAM,UAAU,KAAK,MAAM,cAAO;EAClC,OAAO,UAAU,QAAQ,KAAK;CAChC;CAEA,MAAM,MACJ,QACA,YACsB;EACtB,MAAM,YAAY,YAAY,SAAS;EACvC,MAAM,WAAW,OAAO,KAAK;EAE7B,MAAM,oBAAoB,CAAC;EAE3B,MAAM,kBAAkB,MAAM,KAAK,sBAAsB,KACvD;GAAE;GAAU,QAAQ,KAAK,MAAM,UAAU;EAAE,GAC3C,SACF;EAEA,MAAM,kBAAkB,KAAK,cAAc,gBAAgB,IAAI;EAE/D,MAAM,YAAY,WAAW,qBAAqB;EAClD,MAAM,YAAY,WAAW,GAAG,gBAAgB,SAAS;EAEzD,kBAAkB,KAAK,EAAE,OAAO,gBAAgB,CAAC;EAEjD,IAAI;EACJ,MAAM,UAAU,MAAM,KAAK,MAAM,MAAM,iBAAiB,EACtD,MAAM,KAAK,KACb,CAAC;EAED,IAAI,KAAK,cACP,cAAc,GAAG,KAAK,YAAY,QAAQ;OACrC;GACL,MAAM,YAAY,WAAW,iBAAiB;GAC9C,MAAM,YAAY,WAAW,GAAG,QAAQ,SAAS;GAEjD,kBAAkB,KAAK,EAAE,QAAQ,CAAC;GAElC,MAAM,SAAS,MAAM,KAAK,QAAQ,KAChC;IAAE;IAAU,SAAS,KAAK,UAAU,OAAO;GAAE,GAC7C,SACF;GAEA,cAAc,GACX,KAAK,YAAY,OAAO,KAAK,QAAQ,WACxC;EACF;EAEA,IAAI,KAAK,yBACP,YAAY,0BAA0B;EAGxC,OAAO;CACT;AACF"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
require("./prompts.cjs");
|
|
2
|
-
require("./cypher.cjs");
|
|
1
|
+
const require_prompts = require("./prompts.cjs");
|
|
2
|
+
const require_cypher = require("./cypher.cjs");
|
|
3
|
+
exports.CYPHER_GENERATION_PROMPT = require_prompts.CYPHER_GENERATION_PROMPT;
|
|
4
|
+
exports.CYPHER_QA_PROMPT = require_prompts.CYPHER_QA_PROMPT;
|
|
5
|
+
exports.GraphCypherQAChain = require_cypher.GraphCypherQAChain;
|
|
6
|
+
exports.INTERMEDIATE_STEPS_KEY = require_cypher.INTERMEDIATE_STEPS_KEY;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { FromLLMInput, GraphCypherQAChain, GraphCypherQAChainInput, INTERMEDIATE_STEPS_KEY } from "./cypher.cjs";
|
|
2
|
-
import { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT } from "./prompts.cjs";
|
|
2
|
+
import { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT } from "./prompts.cjs";
|
|
3
|
+
export { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT, type FromLLMInput, GraphCypherQAChain, type GraphCypherQAChainInput, INTERMEDIATE_STEPS_KEY };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { FromLLMInput, GraphCypherQAChain, GraphCypherQAChainInput, INTERMEDIATE_STEPS_KEY } from "./cypher.js";
|
|
2
|
-
import { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT } from "./prompts.js";
|
|
2
|
+
import { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT } from "./prompts.js";
|
|
3
|
+
export { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT, type FromLLMInput, GraphCypherQAChain, type GraphCypherQAChainInput, INTERMEDIATE_STEPS_KEY };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./prompts.js";
|
|
2
|
-
import "./cypher.js";
|
|
3
|
-
export {};
|
|
1
|
+
import { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT } from "./prompts.js";
|
|
2
|
+
import { GraphCypherQAChain, INTERMEDIATE_STEPS_KEY } from "./cypher.js";
|
|
3
|
+
export { CYPHER_GENERATION_PROMPT, CYPHER_QA_PROMPT, GraphCypherQAChain, INTERMEDIATE_STEPS_KEY };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
let _langchain_core_prompts = require("@langchain/core/prompts");
|
|
3
|
-
const CYPHER_GENERATION_PROMPT = /*
|
|
2
|
+
const CYPHER_GENERATION_PROMPT = /* #__PURE__ */ new _langchain_core_prompts.PromptTemplate({
|
|
4
3
|
template: `Task:Generate Cypher statement to query a graph database.
|
|
5
4
|
Instructions:
|
|
6
5
|
Use only the provided relationship types and properties in the schema.
|
|
@@ -15,7 +14,7 @@ The question is:
|
|
|
15
14
|
{question}`,
|
|
16
15
|
inputVariables: ["schema", "question"]
|
|
17
16
|
});
|
|
18
|
-
const CYPHER_QA_PROMPT = /*
|
|
17
|
+
const CYPHER_QA_PROMPT = /* #__PURE__ */ new _langchain_core_prompts.PromptTemplate({
|
|
19
18
|
template: `You are an assistant that helps to form nice and human understandable answers.
|
|
20
19
|
The information part contains the provided information that you must use to construct an answer.
|
|
21
20
|
The provided information is authoritative, you must never doubt it or try to use your internal knowledge to correct it.
|
|
@@ -1 +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":"
|
|
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,UAAU;;;;;;;;;;;;CACV,gBAAgB,CAAC,UAAU,UAAU;AACvC,CAAC;AAmBD,MAAa,mCAAmC,IAAIA,wBAAAA,eAAe;CACjE,UAAU;;;;;;;;;;;;;;;;;CACV,gBAAgB,CAAC,WAAW,UAAU;AACxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.cts","names":[],"sources":["../../../src/chains/graph_qa/prompts.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompts.d.cts","names":[],"sources":["../../../src/chains/graph_qa/prompts.ts"],"mappings":";;cAca,0BAAwB;;;;cAsBxB,kBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","names":[],"sources":["../../../src/chains/graph_qa/prompts.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","names":[],"sources":["../../../src/chains/graph_qa/prompts.ts"],"mappings":";;cAca,0BAAwB;;;;cAsBxB,kBAAgB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
2
|
-
const CYPHER_GENERATION_PROMPT = /*
|
|
2
|
+
const CYPHER_GENERATION_PROMPT = /* #__PURE__ */ new PromptTemplate({
|
|
3
3
|
template: `Task:Generate Cypher statement to query a graph database.
|
|
4
4
|
Instructions:
|
|
5
5
|
Use only the provided relationship types and properties in the schema.
|
|
@@ -14,7 +14,7 @@ The question is:
|
|
|
14
14
|
{question}`,
|
|
15
15
|
inputVariables: ["schema", "question"]
|
|
16
16
|
});
|
|
17
|
-
const CYPHER_QA_PROMPT = /*
|
|
17
|
+
const CYPHER_QA_PROMPT = /* #__PURE__ */ new PromptTemplate({
|
|
18
18
|
template: `You are an assistant that helps to form nice and human understandable answers.
|
|
19
19
|
The information part contains the provided information that you must use to construct an answer.
|
|
20
20
|
The provided information is authoritative, you must never doubt it or try to use your internal knowledge to correct it.
|
|
@@ -1 +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,UAAU;;;;;;;;;;;;CACV,gBAAgB,CAAC,UAAU,
|
|
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,UAAU;;;;;;;;;;;;CACV,gBAAgB,CAAC,UAAU,UAAU;AACvC,CAAC;AAmBD,MAAa,mCAAmC,IAAI,eAAe;CACjE,UAAU;;;;;;;;;;;;;;;;;CACV,gBAAgB,CAAC,WAAW,UAAU;AACxC,CAAC"}
|
package/dist/graphs/document.cjs
CHANGED
|
@@ -1 +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// oxlint-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":"
|
|
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// oxlint-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;CAAe;CAErD,YAAY,EACV,IACA,OAAO,QACP,aAAa,CAAC,KAKb;EACD,MAAM;EACN,KAAK,KAAK;EACV,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;AAEA,IAAa,eAAb,cAAkCA,kCAAAA,aAAa;CAC7C;CAEA;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;CAAuB;CAE7D,YAAY,EACV,QACA,QACA,MACA,aAAa,CAAC,KAMb;EACD,MAAM;EACN,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;AAEA,IAAa,gBAAb,cAAmCA,kCAAAA,aAAa;CAC9C;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;CAAgB;CAEtD,YAAY,EACV,OACA,eACA,UAKC;EACD,MAAM;GACJ;GACA;GACA;EACF,CAAC;EACD,KAAK,QAAQ;EACb,KAAK,gBAAgB;EACrB,KAAK,SAAS;CAChB;AACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Serializable } from "@langchain/core/load/serializable";
|
|
2
2
|
import { Document } from "@langchain/core/documents";
|
|
3
|
-
|
|
4
3
|
//#region src/graphs/document.d.ts
|
|
5
4
|
type Any = any;
|
|
6
5
|
declare class Node extends Serializable {
|
|
@@ -8,11 +7,7 @@ declare class Node extends Serializable {
|
|
|
8
7
|
type: string;
|
|
9
8
|
properties: Record<string, Any>;
|
|
10
9
|
lc_namespace: string[];
|
|
11
|
-
constructor({
|
|
12
|
-
id,
|
|
13
|
-
type,
|
|
14
|
-
properties
|
|
15
|
-
}: {
|
|
10
|
+
constructor({ id, type, properties }: {
|
|
16
11
|
id: string | number;
|
|
17
12
|
type: string;
|
|
18
13
|
properties?: Record<string, Any>;
|
|
@@ -24,12 +19,7 @@ declare class Relationship extends Serializable {
|
|
|
24
19
|
type: string;
|
|
25
20
|
properties: Record<string, Any>;
|
|
26
21
|
lc_namespace: string[];
|
|
27
|
-
constructor({
|
|
28
|
-
source,
|
|
29
|
-
target,
|
|
30
|
-
type,
|
|
31
|
-
properties
|
|
32
|
-
}: {
|
|
22
|
+
constructor({ source, target, type, properties }: {
|
|
33
23
|
source: Node;
|
|
34
24
|
target: Node;
|
|
35
25
|
type: string;
|
|
@@ -41,11 +31,7 @@ declare class GraphDocument extends Serializable {
|
|
|
41
31
|
relationships: Relationship[];
|
|
42
32
|
source: Document;
|
|
43
33
|
lc_namespace: string[];
|
|
44
|
-
constructor({
|
|
45
|
-
nodes,
|
|
46
|
-
relationships,
|
|
47
|
-
source
|
|
48
|
-
}: {
|
|
34
|
+
constructor({ nodes, relationships, source }: {
|
|
49
35
|
nodes: Node[];
|
|
50
36
|
relationships: Relationship[];
|
|
51
37
|
source: Document;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.cts","names":[],"sources":["../../src/graphs/document.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"document.d.cts","names":[],"sources":["../../src/graphs/document.ts"],"mappings":";;;KAIK;cAEQ,aAAa;EACxB;EAEA;EAEA,YAAY,eAAe;EAE3B;EAEA,cACE,IACA,MACA;IAEA;IACA;IACA,aAAa,eAAe;;;cASnB,qBAAqB;EAChC,QAAQ;EAER,QAAQ;EAER;EAEA,YAAY,eAAe;EAE3B;EAEA,cACE,QACA,QACA,MACA;IAEA,QAAQ;IACR,QAAQ;IACR;IACA,aAAa,eAAe;;;cAUnB,sBAAsB;EACjC,OAAO;EAEP,eAAe;EAEf,QAAQ;EAER;EAEA,cACE,OACA,eACA;IAEA,OAAO;IACP,eAAe;IACf,QAAQ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Serializable } from "@langchain/core/load/serializable";
|
|
2
2
|
import { Document } from "@langchain/core/documents";
|
|
3
|
-
|
|
4
3
|
//#region src/graphs/document.d.ts
|
|
5
4
|
type Any = any;
|
|
6
5
|
declare class Node extends Serializable {
|
|
@@ -8,11 +7,7 @@ declare class Node extends Serializable {
|
|
|
8
7
|
type: string;
|
|
9
8
|
properties: Record<string, Any>;
|
|
10
9
|
lc_namespace: string[];
|
|
11
|
-
constructor({
|
|
12
|
-
id,
|
|
13
|
-
type,
|
|
14
|
-
properties
|
|
15
|
-
}: {
|
|
10
|
+
constructor({ id, type, properties }: {
|
|
16
11
|
id: string | number;
|
|
17
12
|
type: string;
|
|
18
13
|
properties?: Record<string, Any>;
|
|
@@ -24,12 +19,7 @@ declare class Relationship extends Serializable {
|
|
|
24
19
|
type: string;
|
|
25
20
|
properties: Record<string, Any>;
|
|
26
21
|
lc_namespace: string[];
|
|
27
|
-
constructor({
|
|
28
|
-
source,
|
|
29
|
-
target,
|
|
30
|
-
type,
|
|
31
|
-
properties
|
|
32
|
-
}: {
|
|
22
|
+
constructor({ source, target, type, properties }: {
|
|
33
23
|
source: Node;
|
|
34
24
|
target: Node;
|
|
35
25
|
type: string;
|
|
@@ -41,11 +31,7 @@ declare class GraphDocument extends Serializable {
|
|
|
41
31
|
relationships: Relationship[];
|
|
42
32
|
source: Document;
|
|
43
33
|
lc_namespace: string[];
|
|
44
|
-
constructor({
|
|
45
|
-
nodes,
|
|
46
|
-
relationships,
|
|
47
|
-
source
|
|
48
|
-
}: {
|
|
34
|
+
constructor({ nodes, relationships, source }: {
|
|
49
35
|
nodes: Node[];
|
|
50
36
|
relationships: Relationship[];
|
|
51
37
|
source: Document;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","names":[],"sources":["../../src/graphs/document.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"document.d.ts","names":[],"sources":["../../src/graphs/document.ts"],"mappings":";;;KAIK;cAEQ,aAAa;EACxB;EAEA;EAEA,YAAY,eAAe;EAE3B;EAEA,cACE,IACA,MACA;IAEA;IACA;IACA,aAAa,eAAe;;;cASnB,qBAAqB;EAChC,QAAQ;EAER,QAAQ;EAER;EAEA,YAAY,eAAe;EAE3B;EAEA,cACE,QACA,QACA,MACA;IAEA,QAAQ;IACR,QAAQ;IACR;IACA,aAAa,eAAe;;;cAUnB,sBAAsB;EACjC,OAAO;EAEP,eAAe;EAEf,QAAQ;EAER;EAEA,cACE,OACA,eACA;IAEA,OAAO;IACP,eAAe;IACf,QAAQ"}
|
|
@@ -1 +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// oxlint-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;
|
|
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// oxlint-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;CAAe;CAErD,YAAY,EACV,IACA,OAAO,QACP,aAAa,CAAC,KAKb;EACD,MAAM;EACN,KAAK,KAAK;EACV,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;AAEA,IAAa,eAAb,cAAkC,aAAa;CAC7C;CAEA;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;CAAuB;CAE7D,YAAY,EACV,QACA,QACA,MACA,aAAa,CAAC,KAMb;EACD,MAAM;EACN,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;AAEA,IAAa,gBAAb,cAAmC,aAAa;CAC9C;CAEA;CAEA;CAEA,eAAe;EAAC;EAAa;EAAS;CAAgB;CAEtD,YAAY,EACV,OACA,eACA,UAKC;EACD,MAAM;GACJ;GACA;GACA;EACF,CAAC;EACD,KAAK,QAAQ;EACb,KAAK,gBAAgB;EACrB,KAAK,SAAS;CAChB;AACF"}
|
package/dist/graphs/index.cjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
require("./neo4j_graph.cjs");
|
|
2
|
-
require("./memgraph_graph.cjs");
|
|
3
|
-
require("./document.cjs");
|
|
1
|
+
const require_neo4j_graph = require("./neo4j_graph.cjs");
|
|
2
|
+
const require_memgraph_graph = require("./memgraph_graph.cjs");
|
|
3
|
+
const require_document = require("./document.cjs");
|
|
4
|
+
exports.BASE_ENTITY_LABEL = require_neo4j_graph.BASE_ENTITY_LABEL;
|
|
5
|
+
exports.GraphDocument = require_document.GraphDocument;
|
|
6
|
+
exports.MemgraphGraph = require_memgraph_graph.MemgraphGraph;
|
|
7
|
+
exports.Neo4jGraph = require_neo4j_graph.Neo4jGraph;
|
|
8
|
+
exports.Node = require_document.Node;
|
|
9
|
+
exports.Relationship = require_document.Relationship;
|
|
10
|
+
exports.formatSchema = require_neo4j_graph.formatSchema;
|
package/dist/graphs/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GraphDocument, Node, Relationship } from "./document.cjs";
|
|
2
2
|
import { AddGraphDocumentsConfig, BASE_ENTITY_LABEL, Neo4jGraph, Neo4jGraphConfig, NodeType, PathType, RelType, StructuredSchema, formatSchema } from "./neo4j_graph.cjs";
|
|
3
|
-
import { MemgraphGraph, MemgraphGraphConfig } from "./memgraph_graph.cjs";
|
|
3
|
+
import { MemgraphGraph, MemgraphGraphConfig } from "./memgraph_graph.cjs";
|
|
4
|
+
export { type AddGraphDocumentsConfig, BASE_ENTITY_LABEL, GraphDocument, MemgraphGraph, type MemgraphGraphConfig, Neo4jGraph, type Neo4jGraphConfig, Node, type NodeType, type PathType, type RelType, Relationship, type StructuredSchema, formatSchema };
|
package/dist/graphs/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GraphDocument, Node, Relationship } from "./document.js";
|
|
2
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";
|
|
3
|
+
import { MemgraphGraph, MemgraphGraphConfig } from "./memgraph_graph.js";
|
|
4
|
+
export { type AddGraphDocumentsConfig, BASE_ENTITY_LABEL, GraphDocument, MemgraphGraph, type MemgraphGraphConfig, Neo4jGraph, type Neo4jGraphConfig, Node, type NodeType, type PathType, type RelType, Relationship, type StructuredSchema, formatSchema };
|
package/dist/graphs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./neo4j_graph.js";
|
|
2
|
-
import "./memgraph_graph.js";
|
|
3
|
-
import "./document.js";
|
|
4
|
-
export {};
|
|
1
|
+
import { BASE_ENTITY_LABEL, Neo4jGraph, formatSchema } from "./neo4j_graph.js";
|
|
2
|
+
import { MemgraphGraph } from "./memgraph_graph.js";
|
|
3
|
+
import { GraphDocument, Node, Relationship } from "./document.js";
|
|
4
|
+
export { BASE_ENTITY_LABEL, GraphDocument, MemgraphGraph, Neo4jGraph, Node, Relationship, formatSchema };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memgraph_graph.cjs","names":["Neo4jGraph","error"],"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;
|
|
1
|
+
{"version":3,"file":"memgraph_graph.cjs","names":["Neo4jGraph","error"],"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;EACtB,MAAM;GAAE;GAAK;GAAU;GAAU;EAAS,CAAC;CAC7C;CAEA,aAAa,WAAW,QAAqD;EAC3E,MAAM,QAAQ,IAAI,cAAc,MAAM;EAEtC,IAAI;GACF,MAAM,MAAM,mBAAmB;EACjC,QAAQ;GACN,QAAQ,MAAM,8BAA8B;EAC9C;EAEA,IAAI;GACF,MAAM,MAAM,cAAc;GAC1B,QAAQ,MAAM,gCAAgC;EAChD,SAAS,GAAG;GAEV,MAAM,IAAI,MAAMC,EAAM,OAAO;EAC/B;EAEA,OAAO;CACT;CAEA,MAAM,gBAAgB;EACpB,MAAM,uBAAuB,MAAM,KAAK,MAAM,cAAc;EAC5D,IAAI,uBAAuB,EAAE,EAAE,QAAQ;GACrC,MAAM,YAAY,uBAAuB,EAAE,EAAE;GAE7C,KAAK,mBAAmB;IACtB,WAAW,UAAU;IACrB,UAAU,UAAU;IACpB,eAAe,UAAU;GAC3B;GAEA,MAAM,qBAAqB,OAAO,QAAQ,UAAU,UAAU,CAAC,CAC5D,KAAK,CAAC,UAAU,gBAAgB;IAE/B,OAAO,eAAe,SAAS,sBADT,KAAK,UAAU,UAC4B;GACnE,CAAC,CAAC,CACD,KAAK,IAAI;GAEZ,MAAM,oBAAoB,OAAO,QAAQ,UAAU,SAAS,CAAC,CAC1D,KAAK,CAAC,kBAAkB,gBAAgB;IAEvC,OAAO,uBAAuB,iBAAiB,8BADzB,KAAK,UAAU,UACoD;GAC3F,CAAC,CAAC,CACD,KAAK,IAAI;GAEZ,MAAM,gBAAgB,UAAU,eAC5B,KACC,OACC,KAAK,GAAG,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,EAC9C,CAAC,CACA,KAAK,IAAI;GAEZ,KAAK,SAAS;IACZ;IACA;IACA;IACA;IACA;IACA;GACF,CAAC,CAAC,KAAK,IAAI;EACb;CACF;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Neo4jGraph } from "./neo4j_graph.cjs";
|
|
2
|
-
|
|
3
2
|
//#region src/graphs/memgraph_graph.d.ts
|
|
4
3
|
interface MemgraphGraphConfig {
|
|
5
4
|
url: string;
|
|
@@ -22,12 +21,7 @@ interface MemgraphGraphConfig {
|
|
|
22
21
|
* @link See https://js.langchain.com/docs/security for more information.
|
|
23
22
|
*/
|
|
24
23
|
declare class MemgraphGraph extends Neo4jGraph {
|
|
25
|
-
constructor({
|
|
26
|
-
url,
|
|
27
|
-
username,
|
|
28
|
-
password,
|
|
29
|
-
database
|
|
30
|
-
}: MemgraphGraphConfig);
|
|
24
|
+
constructor({ url, username, password, database }: MemgraphGraphConfig);
|
|
31
25
|
static initialize(config: MemgraphGraphConfig): Promise<MemgraphGraph>;
|
|
32
26
|
refreshSchema(): Promise<void>;
|
|
33
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memgraph_graph.d.cts","names":[],"sources":["../../src/graphs/memgraph_graph.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"memgraph_graph.d.cts","names":[],"sources":["../../src/graphs/memgraph_graph.ts"],"mappings":";;UAEiB;EACf;EACA;EACA;EACA;;;;;;;;;;;;;;;;cAuBW,sBAAsB;EACjC,cACE,KACA,UACA,UACA,YACC;SAIU,WAAW,QAAQ,sBAAsB,QAAQ;EAoBxD,iBAAa"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Neo4jGraph } from "./neo4j_graph.js";
|
|
2
|
-
|
|
3
2
|
//#region src/graphs/memgraph_graph.d.ts
|
|
4
3
|
interface MemgraphGraphConfig {
|
|
5
4
|
url: string;
|
|
@@ -22,12 +21,7 @@ interface MemgraphGraphConfig {
|
|
|
22
21
|
* @link See https://js.langchain.com/docs/security for more information.
|
|
23
22
|
*/
|
|
24
23
|
declare class MemgraphGraph extends Neo4jGraph {
|
|
25
|
-
constructor({
|
|
26
|
-
url,
|
|
27
|
-
username,
|
|
28
|
-
password,
|
|
29
|
-
database
|
|
30
|
-
}: MemgraphGraphConfig);
|
|
24
|
+
constructor({ url, username, password, database }: MemgraphGraphConfig);
|
|
31
25
|
static initialize(config: MemgraphGraphConfig): Promise<MemgraphGraph>;
|
|
32
26
|
refreshSchema(): Promise<void>;
|
|
33
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memgraph_graph.d.ts","names":[],"sources":["../../src/graphs/memgraph_graph.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"memgraph_graph.d.ts","names":[],"sources":["../../src/graphs/memgraph_graph.ts"],"mappings":";;UAEiB;EACf;EACA;EACA;EACA;;;;;;;;;;;;;;;;cAuBW,sBAAsB;EACjC,cACE,KACA,UACA,UACA,YACC;SAIU,WAAW,QAAQ,sBAAsB,QAAQ;EAoBxD,iBAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memgraph_graph.js","names":["error"],"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,sBAAsB,WAAW;CAC5C,YAAY,EACV,KACA,UACA,UACA,WAAW,cACW;
|
|
1
|
+
{"version":3,"file":"memgraph_graph.js","names":["error"],"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,sBAAsB,WAAW;CAC5C,YAAY,EACV,KACA,UACA,UACA,WAAW,cACW;EACtB,MAAM;GAAE;GAAK;GAAU;GAAU;EAAS,CAAC;CAC7C;CAEA,aAAa,WAAW,QAAqD;EAC3E,MAAM,QAAQ,IAAI,cAAc,MAAM;EAEtC,IAAI;GACF,MAAM,MAAM,mBAAmB;EACjC,QAAQ;GACN,QAAQ,MAAM,8BAA8B;EAC9C;EAEA,IAAI;GACF,MAAM,MAAM,cAAc;GAC1B,QAAQ,MAAM,gCAAgC;EAChD,SAAS,GAAG;GAEV,MAAM,IAAI,MAAMA,EAAM,OAAO;EAC/B;EAEA,OAAO;CACT;CAEA,MAAM,gBAAgB;EACpB,MAAM,uBAAuB,MAAM,KAAK,MAAM,cAAc;EAC5D,IAAI,uBAAuB,EAAE,EAAE,QAAQ;GACrC,MAAM,YAAY,uBAAuB,EAAE,EAAE;GAE7C,KAAK,mBAAmB;IACtB,WAAW,UAAU;IACrB,UAAU,UAAU;IACpB,eAAe,UAAU;GAC3B;GAEA,MAAM,qBAAqB,OAAO,QAAQ,UAAU,UAAU,CAAC,CAC5D,KAAK,CAAC,UAAU,gBAAgB;IAE/B,OAAO,eAAe,SAAS,sBADT,KAAK,UAAU,UAC4B;GACnE,CAAC,CAAC,CACD,KAAK,IAAI;GAEZ,MAAM,oBAAoB,OAAO,QAAQ,UAAU,SAAS,CAAC,CAC1D,KAAK,CAAC,kBAAkB,gBAAgB;IAEvC,OAAO,uBAAuB,iBAAiB,8BADzB,KAAK,UAAU,UACoD;GAC3F,CAAC,CAAC,CACD,KAAK,IAAI;GAEZ,MAAM,gBAAgB,UAAU,eAC5B,KACC,OACC,KAAK,GAAG,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,EAC9C,CAAC,CACA,KAAK,IAAI;GAEZ,KAAK,SAAS;IACZ;IACA;IACA;IACA;IACA;IACA;GACF,CAAC,CAAC,KAAK,IAAI;EACb;CACF;AACF"}
|