@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 @@
1
+ {"version":3,"file":"neo4j_graph.cjs","names":["neo4j"],"sources":["../../src/graphs/neo4j_graph.ts"],"sourcesContent":["import neo4j, {\n RoutingControl,\n type Driver as Neo4jDriver,\n type Record as Neo4jRecord,\n type Path as Neo4jPath,\n} from \"neo4j-driver\";\nimport { sha256 } from \"@langchain/core/utils/hash\";\nimport { GraphDocument } from \"./document.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Any = any;\n\nexport interface Neo4jGraphConfig {\n url: string;\n username: string;\n password: string;\n database?: string;\n timeoutMs?: number;\n enhancedSchema?: boolean;\n}\n\nexport interface StructuredSchema {\n nodeProps: { [key: NodeType[\"labels\"]]: NodeType[\"properties\"] };\n relProps: { [key: RelType[\"type\"]]: RelType[\"properties\"] };\n relationships: PathType[];\n metadata?: {\n constraint: Record<string, Any>;\n index: Record<string, Any>;\n };\n}\n\nexport interface AddGraphDocumentsConfig {\n baseEntityLabel?: boolean;\n includeSource?: boolean;\n}\n\nexport type NodeType = {\n labels: string;\n properties: { property: string; type: string }[];\n};\n\nexport type RelType = {\n type: string;\n properties: { property: string; type: string }[];\n};\n\nexport type PathType = { start: string; type: string; end: string };\n\nexport const BASE_ENTITY_LABEL = \"__Entity__\";\n\nconst DISTINCT_VALUE_LIMIT = 10;\nconst LIST_LIMIT = 128;\nconst EXHAUSTIVE_SEARCH_LIMIT = 10000;\nconst EXCLUDED_LABELS = [\"Bloom_Perspective\", \"Bloom_Scene\"];\nconst EXCLUDED_RELS = [\"Bloom_HAS_SCENE\"];\n\nconst INCLUDE_DOCS_QUERY = `\nMERGE (d:Document {id:$document.metadata.id})\nSET d.text = $document.pageContent\nSET d += $document.metadata\nWITH d\n`;\n\nconst NODE_PROPERTIES_QUERY = `\nCALL apoc.meta.data()\nYIELD label, other, elementType, type, property\nWHERE NOT type = \"RELATIONSHIP\" AND elementType = \"node\"\n AND NOT label IN $EXCLUDED_LABELS\nWITH label AS nodeLabels, collect({property:property, type:type}) AS properties\nRETURN {labels: nodeLabels, properties: properties} AS output\n`;\n\nconst REL_PROPERTIES_QUERY = `\nCALL apoc.meta.data()\nYIELD label, other, elementType, type, property\nWHERE NOT type = \"RELATIONSHIP\" AND elementType = \"relationship\"\n AND NOT label in $EXCLUDED_LABELS\nWITH label AS nodeLabels, collect({property:property, type:type}) AS properties\nRETURN {type: nodeLabels, properties: properties} AS output\n`;\n\nconst REL_QUERY = `\nCALL apoc.meta.data()\nYIELD label, other, elementType, type, property\nWHERE type = \"RELATIONSHIP\" AND elementType = \"node\"\nUNWIND other AS other_node\nWITH * WHERE NOT label IN $EXCLUDED_LABELS\n AND NOT other_node IN $EXCLUDED_LABELS\nRETURN {start: label, type: property, end: toString(other_node)} AS output\n`;\n\nfunction isDistinctMoreThanLimit(\n distinct_count = 11,\n limit = DISTINCT_VALUE_LIMIT\n): boolean {\n return distinct_count !== undefined && distinct_count > limit;\n}\n\nfunction cleanStringValues(text: string) {\n return text.replace(/\\n/g, \" \").replace(/\\r/g, \" \");\n}\n\nexport function formatSchema(\n schema: Record<string, Any>,\n isEnhanced: boolean\n): string {\n let formattedNodeProps: string[] = [];\n let formattedRelProps: string[] = [];\n\n if (isEnhanced) {\n for (const [nodeType, properties] of Object.entries(schema.nodeProps)) {\n formattedNodeProps.push(`- **${nodeType}**`);\n\n for (const prop of properties as Array<Record<string, Any>>) {\n let example = \"\";\n\n if (prop.type === \"STRING\") {\n if (prop.values.length > 0) {\n if (isDistinctMoreThanLimit(prop.distinct_count)) {\n example = `Example: ${cleanStringValues(prop.values[0])}`;\n } else {\n example = `Available options: ${prop.values\n .map(cleanStringValues)\n .join(\", \")}`;\n }\n }\n } else if (\n [\"INTEGER\", \"FLOAT\", \"DATE\", \"DATE_TIME\", \"LOCAL_DATE_TIME\"].includes(\n prop.type\n )\n ) {\n if (prop.min !== undefined) {\n example = `Min: ${prop.min}, Max: ${prop.max}`;\n } else {\n if (prop.values.length > 0) {\n example = `Example: ${prop.values[0]}`;\n }\n }\n } else if (prop.type === \"LIST\") {\n if (!prop.min_size || prop.min_size > LIST_LIMIT) {\n continue;\n }\n example = `Min Size: ${prop.min_size}, Max Size: ${prop.max_size}`;\n }\n\n formattedNodeProps.push(\n ` - \\`${prop.property}\\`: ${prop.type} ${example}`\n );\n }\n }\n\n for (const [relType, properties] of Object.entries(schema.relProps)) {\n formattedRelProps.push(`- **${relType}**`);\n\n for (const prop of properties as Array<Record<string, Any>>) {\n let example = \"\";\n\n if (prop.type === \"STRING\") {\n if (prop.values.length > 0) {\n if (isDistinctMoreThanLimit(prop.distinct_count)) {\n example = `Example: ${cleanStringValues(prop.values[0])}`;\n } else {\n example = `Available options: ${prop.values\n .map(cleanStringValues)\n .join(\", \")}`;\n }\n }\n } else if (\n [\"INTEGER\", \"FLOAT\", \"DATE\", \"DATE_TIME\", \"LOCAL_DATE_TIME\"].includes(\n prop.type\n )\n ) {\n if (prop.min) {\n example = `Min: ${prop.min}, Max: ${prop.max}`;\n } else {\n if (prop.values) {\n example = `Example: ${prop.values[0]}`;\n }\n }\n } else if (prop.type === \"LIST\") {\n if (prop.min_size > LIST_LIMIT) {\n continue;\n }\n example = `Min Size: ${prop.min_size}, Max Size: ${prop.max_size}`;\n }\n\n formattedRelProps.push(\n ` - \\`${prop.property}\\`: ${prop.type} ${example}`\n );\n }\n }\n } else {\n formattedNodeProps = Object.entries(schema.nodeProps).map(\n ([key, value]: [string, Any]) => {\n const propsStr = value\n .map((prop: Record<string, Any>) => `${prop.property}: ${prop.type}`)\n .join(\", \");\n return `${key} {${propsStr}}`;\n }\n );\n\n formattedRelProps = Object.entries(schema.relProps).map(\n ([key, value]: [string, Any]) => {\n const propsStr = value\n .map((prop: Record<string, Any>) => `${prop.property}: ${prop.type} `)\n .join(\", \");\n return `${key} {${propsStr} } `;\n }\n );\n }\n\n const formattedRels = schema.relationships.map(\n (el: Record<string, string>) =>\n `(: ${el.start}) - [: ${el.type}] -> (:${el.end})`\n );\n\n return [\n \"Node properties are the following:\",\n formattedNodeProps?.join(\", \"),\n \"Relationship properties are the following:\",\n formattedRelProps?.join(\", \"),\n \"The relationships are the following:\",\n formattedRels?.join(\", \"),\n ].join(\"\\n\");\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 Neo4jGraph {\n private driver: Neo4jDriver;\n\n private database: string;\n\n private timeoutMs: number | undefined;\n\n private enhancedSchema: boolean;\n\n protected schema = \"\";\n\n protected structuredSchema: StructuredSchema = {\n nodeProps: {},\n relProps: {},\n relationships: [],\n metadata: {\n constraint: {},\n index: {},\n },\n };\n\n constructor({\n url,\n username,\n password,\n database = \"neo4j\",\n timeoutMs,\n enhancedSchema = false,\n }: Neo4jGraphConfig) {\n try {\n this.driver = neo4j.driver(url, neo4j.auth.basic(username, password));\n this.database = database;\n this.timeoutMs = timeoutMs;\n this.enhancedSchema = enhancedSchema;\n } catch {\n throw new Error(\n \"Could not create a Neo4j driver instance. Please check the connection details.\"\n );\n }\n }\n\n static async initialize(config: Neo4jGraphConfig): Promise<Neo4jGraph> {\n const graph = new Neo4jGraph(config);\n\n await graph.verifyConnectivity();\n\n try {\n await graph.refreshSchema();\n } catch (error: Any) {\n if (error.code === \"Neo.ClientError.Procedure.ProcedureNotFound\") {\n throw new Error(\n \"Could not use APOC procedures. Please ensure the APOC plugin is installed in Neo4j and that 'apoc.meta.data()' is allowed in Neo4j configuration.\"\n );\n }\n\n throw error;\n } finally {\n console.log(\"Schema refreshed successfully.\");\n }\n\n return graph;\n }\n\n getSchema(): string {\n return this.schema;\n }\n\n getStructuredSchema() {\n return this.structuredSchema;\n }\n\n async query<RecordShape extends Record<string, Any> = Record<string, Any>>(\n query: string,\n params: Record<string, Any> = {},\n routing: RoutingControl = neo4j.routing.WRITE\n ): Promise<RecordShape[]> {\n const result = await this.driver.executeQuery<RecordShape>(query, params, {\n database: this.database,\n routing,\n transactionConfig: { timeout: this.timeoutMs },\n });\n return toObjects<RecordShape>(result.records);\n }\n\n async verifyConnectivity() {\n await this.driver.getServerInfo();\n }\n\n async refreshSchema() {\n const nodeProperties = (\n await this.query<{ output: NodeType }>(NODE_PROPERTIES_QUERY, {\n EXCLUDED_LABELS: EXCLUDED_LABELS.concat([BASE_ENTITY_LABEL]),\n })\n )?.map((el) => el.output);\n\n const relationshipsProperties = (\n await this.query<{ output: RelType }>(REL_PROPERTIES_QUERY, {\n EXCLUDED_LABELS: EXCLUDED_RELS,\n })\n )?.map((el) => el.output);\n\n const relationships: PathType[] = (\n await this.query<{ output: PathType }>(REL_QUERY, {\n EXCLUDED_LABELS: EXCLUDED_LABELS.concat([BASE_ENTITY_LABEL]),\n })\n )?.map((el) => el.output);\n\n const constraint = await this.query(\"SHOW CONSTRAINTS\");\n\n const index = await this.query(\"SHOW INDEXES YIELD *\");\n\n this.structuredSchema = {\n nodeProps: Object.fromEntries(\n nodeProperties?.map((el) => [el.labels, el.properties]) || []\n ),\n relProps: Object.fromEntries(\n relationshipsProperties?.map((el) => [el.type, el.properties]) || []\n ),\n relationships: relationships || [],\n metadata: {\n constraint,\n index,\n },\n };\n\n if (this.enhancedSchema) {\n const schemaCounts = await this.query(\n `CALL apoc.meta.graphSample() YIELD nodes, relationships ` +\n `RETURN nodes, [rel in relationships | {name: apoc.any.property(rel, 'type'), count: apoc.any.property(rel, 'count')}] AS relationships`\n );\n for (const node of schemaCounts[0].nodes) {\n if (EXCLUDED_LABELS.includes(node.name)) {\n continue;\n }\n\n const nodeProps = this.structuredSchema.nodeProps[node.name];\n\n if (!nodeProps) {\n continue;\n }\n\n const enhancedCypher = await this.enhancedSchemaCypher(\n node.name,\n nodeProps,\n node.count < EXHAUSTIVE_SEARCH_LIMIT\n );\n const enhancedInfoPromise = await this.query(enhancedCypher);\n const enhancedInfo = enhancedInfoPromise[0].output;\n\n for (const prop of nodeProps) {\n if (enhancedInfo[prop.property]) {\n Object.assign(prop, enhancedInfo[prop.property]);\n }\n }\n }\n\n for (const rel of schemaCounts[0].relationships) {\n if (EXCLUDED_RELS.includes(rel.name)) {\n continue;\n }\n const relProps = this.structuredSchema.relProps[rel.name];\n\n if (!relProps) {\n continue;\n }\n const enhancedCypher = await this.enhancedSchemaCypher(\n rel.name,\n relProps,\n rel.count < EXHAUSTIVE_SEARCH_LIMIT,\n true\n );\n\n const enhancedInfoPromise = await this.query(enhancedCypher);\n const enhancedInfo = enhancedInfoPromise[0].output;\n\n for (const prop of relProps) {\n if (prop.property in enhancedInfo) {\n Object.assign(prop, enhancedInfo[prop.property]);\n }\n }\n }\n }\n\n this.schema = formatSchema(this.structuredSchema, this.enhancedSchema);\n }\n\n async enhancedSchemaCypher(\n labelOrType: string,\n properties: { property: string; type: string }[],\n exhaustive: boolean,\n isRelationship = false\n ) {\n let matchClause = isRelationship\n ? `MATCH ()-[n:\\`${labelOrType}\\`]->()`\n : `MATCH (n:\\`${labelOrType}\\`)`;\n\n const withClauses: string[] = [];\n const returnClauses: string[] = [];\n const outputDict: { [key: string]: string } = {};\n\n if (exhaustive) {\n for (const prop of properties) {\n const propName = prop.property;\n const propType = prop.type;\n\n if (propType === \"STRING\") {\n withClauses.push(\n `collect(distinct substring(n.\\`${propName}\\`, 0, 50)) AS \\`${propName}_values\\``\n );\n returnClauses.push(\n `values: \\`${propName}_values\\`[..${DISTINCT_VALUE_LIMIT}], distinct_count: size(\\`${propName}_values\\`)`\n );\n } else if (\n [\"INTEGER\", \"FLOAT\", \"DATE\", \"DATE_TIME\", \"LOCAL_DATE_TIME\"].includes(\n propType\n )\n ) {\n withClauses.push(`min(n.\\`${propName}\\`) AS \\`${propName}_min\\``);\n withClauses.push(`max(n.\\`${propName}\\`) AS \\`${propName}_max\\``);\n withClauses.push(\n `count(distinct n.\\`${propName}\\`) AS \\`${propName}_distinct\\``\n );\n returnClauses.push(\n `min: toString(\\`${propName}_min\\`), max: toString(\\`${propName}_max\\`), distinct_count: \\`${propName}_distinct\\``\n );\n } else if (propType === \"LIST\") {\n withClauses.push(\n `min(size(n.\\`${propName}\\`)) AS \\`${propName}_size_min\\`, max(size(n.\\`${propName}\\`)) AS \\`${propName}_size_max\\``\n );\n returnClauses.push(\n `min_size: \\`${propName}_size_min\\`, max_size: \\`${propName}_size_max\\``\n );\n } else if ([\"BOOLEAN\", \"POINT\", \"DURATION\"].includes(propType)) {\n continue;\n }\n outputDict[propName] = `{${returnClauses.pop()}}`;\n }\n } else {\n matchClause += ` WITH n LIMIT 5`;\n\n for (const prop of properties) {\n const propName = prop.property;\n const propType = prop.type;\n\n const propIndex = this.structuredSchema?.metadata?.index.filter(\n (el: Any) =>\n el.label === labelOrType &&\n el.properties[0] === propName &&\n el.type === \"RANGE\"\n );\n\n if (propType === \"STRING\") {\n if (\n propIndex.length > 0 &&\n propIndex[0].size > 0 &&\n propIndex[0].distinctValues <= DISTINCT_VALUE_LIMIT\n ) {\n const distinctValuesPromise = await this.query(\n `CALL apoc.schema.properties.distinct('${labelOrType}', '${propName}') YIELD value`\n );\n const distinctValues = distinctValuesPromise[0].value;\n returnClauses.push(\n `values: ${distinctValues}, distinct_count: ${distinctValues.length}`\n );\n } else {\n withClauses.push(\n `collect(distinct substring(n.\\`${propName}\\`, 0, 50)) AS \\`${propName}_values\\``\n );\n returnClauses.push(`values: ${propName}_values`);\n }\n } else if (\n [\"INTEGER\", \"FLOAT\", \"DATE\", \"DATE_TIME\", \"LOCAL_DATE_TIME\"].includes(\n propType\n )\n ) {\n if (!propIndex) {\n withClauses.push(\n `collect(distinct toString(n.\\`${propName}\\`)) AS \\`${propName}_values\\``\n );\n returnClauses.push(`values: ${propName}_values`);\n } else {\n withClauses.push(`min(n.\\`${propName}\\`) AS \\`${propName}_min\\``);\n withClauses.push(`max(n.\\`${propName}\\`) AS \\`${propName}_max\\``);\n withClauses.push(\n `count(distinct n.\\`${propName}\\`) AS \\`${propName}_distinct\\``\n );\n returnClauses.push(\n `min: toString(\\`${propName}_min\\`), max: toString(\\`${propName}_max\\`), distinct_count: \\`${propName}_distinct\\``\n );\n }\n } else if (propType === \"LIST\") {\n withClauses.push(\n `min(size(n.\\`${propName}\\`)) AS \\`${propName}_size_min\\`, max(size(n.\\`${propName}\\`)) AS \\`${propName}_size_max\\``\n );\n returnClauses.push(\n `min_size: \\`${propName}_size_min\\`, max_size: \\`${propName}_size_max\\``\n );\n } else if ([\"BOOLEAN\", \"POINT\", \"DURATION\"].includes(propType)) {\n continue;\n }\n\n outputDict[propName] = `{${returnClauses.pop()}}`;\n }\n }\n\n const withClause = `WITH ${withClauses.join(\", \")}`;\n const returnClause = `RETURN {${Object.entries(outputDict)\n .map(([k, v]) => `\\`${k}\\`: ${v}`)\n .join(\", \")}} AS output`;\n\n const cypherQuery = [matchClause, withClause, returnClause].join(\"\\n\");\n\n return cypherQuery;\n }\n\n async addGraphDocuments(\n graphDocuments: GraphDocument[],\n config: AddGraphDocumentsConfig = {}\n ): Promise<void> {\n const { baseEntityLabel } = config;\n\n if (baseEntityLabel) {\n const constraintExists =\n this.structuredSchema?.metadata?.constraint?.some(\n (el: Any) =>\n JSON.stringify(el.labelsOrTypes) ===\n JSON.stringify([BASE_ENTITY_LABEL]) &&\n JSON.stringify(el.properties) === JSON.stringify([\"id\"])\n ) ?? false;\n\n if (!constraintExists) {\n await this.query(`\n CREATE CONSTRAINT IF NOT EXISTS FOR (b:${BASE_ENTITY_LABEL})\n REQUIRE b.id IS UNIQUE;\n `);\n await this.refreshSchema();\n }\n }\n\n const nodeImportQuery = getNodeImportQuery(config);\n const relImportQuery = getRelImportQuery(config);\n\n for (const document of graphDocuments) {\n if (!document.source.metadata.id) {\n document.source.metadata.id = sha256(document.source.pageContent);\n }\n\n await this.query(nodeImportQuery, {\n data: document.nodes.map((el: Any) => ({ ...el })),\n document: { ...document.source },\n });\n\n await this.query(relImportQuery, {\n data: document.relationships.map((el: Any) => ({\n source: el.source.id,\n source_label: el.source.type,\n target: el.target.id,\n target_label: el.target.type,\n type: el.type.replace(/ /g, \"_\").toUpperCase(),\n properties: el.properties,\n })),\n });\n }\n }\n\n async close() {\n await this.driver.close();\n }\n}\n\nfunction getNodeImportQuery({\n baseEntityLabel,\n includeSource,\n}: AddGraphDocumentsConfig): string {\n if (baseEntityLabel) {\n return `\n ${includeSource ? INCLUDE_DOCS_QUERY : \"\"}\n UNWIND $data AS row\n MERGE(source: \\`${BASE_ENTITY_LABEL}\\` {id: row.id})\n SET source += row.properties\n ${includeSource ? \"MERGE (d)-[:MENTIONS]->(source)\" : \"\"}\n WITH source, row\n CALL apoc.create.addLabels(source, [row.type]) YIELD node\n RETURN distinct 'done' AS result\n `;\n } else {\n return `\n ${includeSource ? INCLUDE_DOCS_QUERY : \"\"}\n UNWIND $data AS row\n CALL apoc.merge.node([row.type], {id: row.id},\n row.properties, {}) YIELD node\n ${includeSource ? \"MERGE (d)-[:MENTIONS]->(node)\" : \"\"}\n RETURN distinct 'done' AS result\n `;\n }\n}\n\nfunction getRelImportQuery({\n baseEntityLabel,\n}: AddGraphDocumentsConfig): string {\n if (baseEntityLabel) {\n return `\n UNWIND $data AS row\n MERGE (source:\\`${BASE_ENTITY_LABEL}\\` {id: row.source})\n MERGE (target:\\`${BASE_ENTITY_LABEL}\\` {id: row.target})\n WITH source, target, row\n CALL apoc.merge.relationship(source, row.type,\n {}, row.properties, target) YIELD rel\n RETURN distinct 'done'\n `;\n } else {\n return `\n UNWIND $data AS row\n CALL apoc.merge.node([row.source_label], {id: row.source},\n {}, {}) YIELD node as source\n CALL apoc.merge.node([row.target_label], {id: row.target},\n {}, {}) YIELD node as target\n CALL apoc.merge.relationship(source, row.type,\n {}, row.properties, target) YIELD rel\n RETURN distinct 'done'\n `;\n }\n}\n\nfunction toObjects<\n RecordShape extends Record<string, Any> = Record<string, Any>,\n>(records: Neo4jRecord<RecordShape>): RecordShape[] {\n return records.map((record: Any) => {\n const rObj = record.toObject();\n const out: Partial<RecordShape> = {};\n Object.keys(rObj).forEach((key: keyof RecordShape) => {\n out[key] = itemIntToString(rObj[key]);\n });\n return out as RecordShape;\n });\n}\n\nfunction itemIntToString(item: Any): Any {\n if (neo4j.isInt(item)) return item.toString();\n if (Array.isArray(item)) return item.map((ii) => itemIntToString(ii));\n if ([\"number\", \"string\", \"boolean\"].indexOf(typeof item) !== -1) return item;\n if (item === null) return item;\n if (typeof item === \"object\") return objIntToString(item);\n}\n\nfunction objIntToString(obj: Any) {\n const entry = extractFromNeoObjects(obj);\n let newObj: Any = null;\n if (Array.isArray(entry)) {\n newObj = entry.map((item) => itemIntToString(item));\n } else if (entry !== null && typeof entry === \"object\") {\n newObj = {};\n Object.keys(entry).forEach((key) => {\n newObj[key] = itemIntToString(entry[key]);\n });\n }\n return newObj;\n}\n\nfunction extractFromNeoObjects(obj: Any) {\n if (\n // eslint-disable-next-line\n obj instanceof (neo4j.types.Node as any) ||\n // eslint-disable-next-line\n obj instanceof (neo4j.types.Relationship as any)\n ) {\n return obj.properties;\n // eslint-disable-next-line\n } else if (obj instanceof (neo4j.types.Path as any)) {\n // eslint-disable-next-line\n return [].concat.apply<any[], any[], any[]>([], extractPathForRows(obj));\n }\n return obj;\n}\n\nconst extractPathForRows = (path: Neo4jPath) => {\n let { segments } = path;\n if (!Array.isArray(path.segments) || path.segments.length < 1) {\n segments = [{ ...path, end: null } as Any];\n }\n\n return segments.map((segment: Any) =>\n [\n objIntToString(segment.start),\n objIntToString(segment.relationship),\n objIntToString(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;AACtD,WAAS,EAAE;AACX,SAAO,KAAK,MAAM,CAAC,SAAS,QAAQ;AAClC,UAAO,OAAO,gBAAgB,MAAM,KAAK;IACzC;;AAEJ,QAAO;;AAGT,SAAS,sBAAsB,KAAU;AACvC,KAEE,eAAgBA,aAAAA,QAAM,MAAM,QAE5B,eAAgBA,aAAAA,QAAM,MAAM,aAE5B,QAAO,IAAI;UAEF,eAAgBA,aAAAA,QAAM,MAAM,KAErC,QAAO,EAAE,CAAC,OAAO,MAA2B,EAAE,EAAE,mBAAmB,IAAI,CAAC;AAE1E,QAAO;;AAGT,MAAM,sBAAsB,SAAoB;CAC9C,IAAI,EAAE,aAAa;AACnB,KAAI,CAAC,MAAM,QAAQ,KAAK,SAAS,IAAI,KAAK,SAAS,SAAS,EAC1D,YAAW,CAAC;EAAE,GAAG;EAAM,KAAK;EAAM,CAAQ;AAG5C,QAAO,SAAS,KAAK,YACnB;EACE,eAAe,QAAQ,MAAM;EAC7B,eAAe,QAAQ,aAAa;EACpC,eAAe,QAAQ,IAAI;EAC5B,CAAC,QAAQ,SAAS,SAAS,KAAK,CAClC"}
@@ -0,0 +1,96 @@
1
+ import { GraphDocument } from "./document.cjs";
2
+ import { RoutingControl } from "neo4j-driver";
3
+
4
+ //#region src/graphs/neo4j_graph.d.ts
5
+ type Any = any;
6
+ interface Neo4jGraphConfig {
7
+ url: string;
8
+ username: string;
9
+ password: string;
10
+ database?: string;
11
+ timeoutMs?: number;
12
+ enhancedSchema?: boolean;
13
+ }
14
+ interface StructuredSchema {
15
+ nodeProps: {
16
+ [key: NodeType["labels"]]: NodeType["properties"];
17
+ };
18
+ relProps: {
19
+ [key: RelType["type"]]: RelType["properties"];
20
+ };
21
+ relationships: PathType[];
22
+ metadata?: {
23
+ constraint: Record<string, Any>;
24
+ index: Record<string, Any>;
25
+ };
26
+ }
27
+ interface AddGraphDocumentsConfig {
28
+ baseEntityLabel?: boolean;
29
+ includeSource?: boolean;
30
+ }
31
+ type NodeType = {
32
+ labels: string;
33
+ properties: {
34
+ property: string;
35
+ type: string;
36
+ }[];
37
+ };
38
+ type RelType = {
39
+ type: string;
40
+ properties: {
41
+ property: string;
42
+ type: string;
43
+ }[];
44
+ };
45
+ type PathType = {
46
+ start: string;
47
+ type: string;
48
+ end: string;
49
+ };
50
+ declare const BASE_ENTITY_LABEL = "__Entity__";
51
+ declare function formatSchema(schema: Record<string, Any>, isEnhanced: boolean): string;
52
+ /**
53
+ * @security *Security note*: Make sure that the database connection uses credentials
54
+ * that are narrowly-scoped to only include necessary permissions.
55
+ * Failure to do so may result in data corruption or loss, since the calling
56
+ * code may attempt commands that would result in deletion, mutation
57
+ * of data if appropriately prompted or reading sensitive data if such
58
+ * data is present in the database.
59
+ * The best way to guard against such negative outcomes is to (as appropriate)
60
+ * limit the permissions granted to the credentials used with this tool.
61
+ * For example, creating read only users for the database is a good way to
62
+ * ensure that the calling code cannot mutate or delete data.
63
+ *
64
+ * @link See https://js.langchain.com/docs/security for more information.
65
+ */
66
+ declare class Neo4jGraph {
67
+ private driver;
68
+ private database;
69
+ private timeoutMs;
70
+ private enhancedSchema;
71
+ protected schema: string;
72
+ protected structuredSchema: StructuredSchema;
73
+ constructor({
74
+ url,
75
+ username,
76
+ password,
77
+ database,
78
+ timeoutMs,
79
+ enhancedSchema
80
+ }: Neo4jGraphConfig);
81
+ static initialize(config: Neo4jGraphConfig): Promise<Neo4jGraph>;
82
+ getSchema(): string;
83
+ getStructuredSchema(): StructuredSchema;
84
+ query<RecordShape extends Record<string, Any> = Record<string, Any>>(query: string, params?: Record<string, Any>, routing?: RoutingControl): Promise<RecordShape[]>;
85
+ verifyConnectivity(): Promise<void>;
86
+ refreshSchema(): Promise<void>;
87
+ enhancedSchemaCypher(labelOrType: string, properties: {
88
+ property: string;
89
+ type: string;
90
+ }[], exhaustive: boolean, isRelationship?: boolean): Promise<string>;
91
+ addGraphDocuments(graphDocuments: GraphDocument[], config?: AddGraphDocumentsConfig): Promise<void>;
92
+ close(): Promise<void>;
93
+ }
94
+ //#endregion
95
+ export { AddGraphDocumentsConfig, BASE_ENTITY_LABEL, Neo4jGraph, Neo4jGraphConfig, NodeType, PathType, RelType, StructuredSchema, formatSchema };
96
+ //# sourceMappingURL=neo4j_graph.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neo4j_graph.d.cts","names":[],"sources":["../../src/graphs/neo4j_graph.ts"],"mappings":";;;;KAUK,GAAA;AAAA,UAEY,gBAAA;EACf,GAAA;EACA,QAAA;EACA,QAAA;EACA,QAAA;EACA,SAAA;EACA,cAAA;AAAA;AAAA,UAGe,gBAAA;EACf,SAAA;IAAA,CAAc,GAAA,EAAK,QAAA,aAAqB,QAAA;EAAA;EACxC,QAAA;IAAA,CAAa,GAAA,EAAK,OAAA,WAAkB,OAAA;EAAA;EACpC,aAAA,EAAe,QAAA;EACf,QAAA;IACE,UAAA,EAAY,MAAA,SAAe,GAAA;IAC3B,KAAA,EAAO,MAAA,SAAe,GAAA;EAAA;AAAA;AAAA,UAIT,uBAAA;EACf,eAAA;EACA,aAAA;AAAA;AAAA,KAGU,QAAA;EACV,MAAA;EACA,UAAA;IAAc,QAAA;IAAkB,IAAA;EAAA;AAAA;AAAA,KAGtB,OAAA;EACV,IAAA;EACA,UAAA;IAAc,QAAA;IAAkB,IAAA;EAAA;AAAA;AAAA,KAGtB,QAAA;EAAa,KAAA;EAAe,IAAA;EAAc,GAAA;AAAA;AAAA,cAEzC,iBAAA;AAAA,iBAsDG,YAAA,CACd,MAAA,EAAQ,MAAA,SAAe,GAAA,GACvB,UAAA;;;;;;AAzEF;;;;;AAKA;;;;cA4Ma,UAAA;EAAA,QACH,MAAA;EAAA,QAEA,QAAA;EAAA,QAEA,SAAA;EAAA,QAEA,cAAA;EAAA,UAEE,MAAA;EAAA,UAEA,gBAAA,EAAkB,gBAAA;EAU5B,WAAA,CAAA;IACE,GAAA;IACA,QAAA;IACA,QAAA;IACA,QAAA;IACA,SAAA;IACA;EAAA,GACC,gBAAA;EAAA,OAaU,UAAA,CAAW,MAAA,EAAQ,gBAAA,GAAmB,OAAA,CAAQ,UAAA;EAsB3D,SAAA,CAAA;EAIA,mBAAA,CAAA,GAAmB,gBAAA;EAIb,KAAA,qBAA0B,MAAA,SAAe,GAAA,IAAO,MAAA,SAAe,GAAA,EAAA,CACnE,KAAA,UACA,MAAA,GAAQ,MAAA,SAAe,GAAA,GACvB,OAAA,GAAS,cAAA,GACR,OAAA,CAAQ,WAAA;EASL,kBAAA,CAAA,GAAkB,OAAA;EAIlB,aAAA,CAAA,GAAa,OAAA;EAkGb,oBAAA,CACJ,WAAA,UACA,UAAA;IAAc,QAAA;IAAkB,IAAA;EAAA,KAChC,UAAA,WACA,cAAA,aAAsB,OAAA;EA6HlB,iBAAA,CACJ,cAAA,EAAgB,aAAA,IAChB,MAAA,GAAQ,uBAAA,GACP,OAAA;EA+CG,KAAA,CAAA,GAAK,OAAA;AAAA"}
@@ -0,0 +1,96 @@
1
+ import { GraphDocument } from "./document.js";
2
+ import { RoutingControl } from "neo4j-driver";
3
+
4
+ //#region src/graphs/neo4j_graph.d.ts
5
+ type Any = any;
6
+ interface Neo4jGraphConfig {
7
+ url: string;
8
+ username: string;
9
+ password: string;
10
+ database?: string;
11
+ timeoutMs?: number;
12
+ enhancedSchema?: boolean;
13
+ }
14
+ interface StructuredSchema {
15
+ nodeProps: {
16
+ [key: NodeType["labels"]]: NodeType["properties"];
17
+ };
18
+ relProps: {
19
+ [key: RelType["type"]]: RelType["properties"];
20
+ };
21
+ relationships: PathType[];
22
+ metadata?: {
23
+ constraint: Record<string, Any>;
24
+ index: Record<string, Any>;
25
+ };
26
+ }
27
+ interface AddGraphDocumentsConfig {
28
+ baseEntityLabel?: boolean;
29
+ includeSource?: boolean;
30
+ }
31
+ type NodeType = {
32
+ labels: string;
33
+ properties: {
34
+ property: string;
35
+ type: string;
36
+ }[];
37
+ };
38
+ type RelType = {
39
+ type: string;
40
+ properties: {
41
+ property: string;
42
+ type: string;
43
+ }[];
44
+ };
45
+ type PathType = {
46
+ start: string;
47
+ type: string;
48
+ end: string;
49
+ };
50
+ declare const BASE_ENTITY_LABEL = "__Entity__";
51
+ declare function formatSchema(schema: Record<string, Any>, isEnhanced: boolean): string;
52
+ /**
53
+ * @security *Security note*: Make sure that the database connection uses credentials
54
+ * that are narrowly-scoped to only include necessary permissions.
55
+ * Failure to do so may result in data corruption or loss, since the calling
56
+ * code may attempt commands that would result in deletion, mutation
57
+ * of data if appropriately prompted or reading sensitive data if such
58
+ * data is present in the database.
59
+ * The best way to guard against such negative outcomes is to (as appropriate)
60
+ * limit the permissions granted to the credentials used with this tool.
61
+ * For example, creating read only users for the database is a good way to
62
+ * ensure that the calling code cannot mutate or delete data.
63
+ *
64
+ * @link See https://js.langchain.com/docs/security for more information.
65
+ */
66
+ declare class Neo4jGraph {
67
+ private driver;
68
+ private database;
69
+ private timeoutMs;
70
+ private enhancedSchema;
71
+ protected schema: string;
72
+ protected structuredSchema: StructuredSchema;
73
+ constructor({
74
+ url,
75
+ username,
76
+ password,
77
+ database,
78
+ timeoutMs,
79
+ enhancedSchema
80
+ }: Neo4jGraphConfig);
81
+ static initialize(config: Neo4jGraphConfig): Promise<Neo4jGraph>;
82
+ getSchema(): string;
83
+ getStructuredSchema(): StructuredSchema;
84
+ query<RecordShape extends Record<string, Any> = Record<string, Any>>(query: string, params?: Record<string, Any>, routing?: RoutingControl): Promise<RecordShape[]>;
85
+ verifyConnectivity(): Promise<void>;
86
+ refreshSchema(): Promise<void>;
87
+ enhancedSchemaCypher(labelOrType: string, properties: {
88
+ property: string;
89
+ type: string;
90
+ }[], exhaustive: boolean, isRelationship?: boolean): Promise<string>;
91
+ addGraphDocuments(graphDocuments: GraphDocument[], config?: AddGraphDocumentsConfig): Promise<void>;
92
+ close(): Promise<void>;
93
+ }
94
+ //#endregion
95
+ export { AddGraphDocumentsConfig, BASE_ENTITY_LABEL, Neo4jGraph, Neo4jGraphConfig, NodeType, PathType, RelType, StructuredSchema, formatSchema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