Feature/Add Neo4j GraphRag support (#3686)

* added: Neo4j database connectivity, Neo4j credentials, supports the usage of the GraphCypherQaChain node and modifies the FewShotPromptTemplate node to handle variables from the prefix field.

* Merge branch 'main' of github.com:FlowiseAI/Flowise into feature/graphragsupport

* revert pnpm-lock.yaml

* add: neo4j package

* Refactor GraphCypherQAChain: Update version to 1.0, remove memory input, and enhance prompt handling

- Changed version from 2.0 to 1.0.
- Removed the 'Memory' input parameter from the GraphCypherQAChain.
- Made 'cypherPrompt' optional and improved error handling for prompt validation.
- Updated the 'init' and 'run' methods to streamline input processing and response handling.
- Enhanced streaming response logic based on the 'returnDirect' flag.

* Refactor GraphCypherQAChain: Simplify imports and update init method signature

- Consolidated import statements for better readability.
- Removed the 'input' and 'options' parameters from the 'init' method, streamlining its signature to only accept 'nodeData'.

* add output, format final response, fix optional inputs

---------

Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
Anthony Bryan Gavilan Vinces
2024-12-22 20:35:53 -05:00
committed by GitHub
parent 93f3a5d98a
commit a7c1ab881c
8 changed files with 34468 additions and 34040 deletions
@@ -0,0 +1,80 @@
import { getBaseClasses, getCredentialData } from '../../../src/utils'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { Neo4jGraph } from '@langchain/community/graphs/neo4j_graph'
class Neo4j_Graphs implements INode {
label: string
name: string
version: number
type: string
icon: string
category: string
description: string
baseClasses: string[]
credential: INodeParams
inputs: INodeParams[]
constructor() {
this.label = 'Neo4j'
this.name = 'Neo4j'
this.version = 1.0
this.type = 'Neo4j'
this.icon = 'neo4j.svg'
this.category = 'Graph'
this.description = 'Connect with Neo4j graph database'
this.baseClasses = [this.type, ...getBaseClasses(Neo4jGraph)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['neo4jApi']
}
this.inputs = [
{
label: 'Database',
name: 'database',
type: 'string',
placeholder: 'neo4j',
optional: true
},
{
label: 'Timeout (ms)',
name: 'timeoutMs',
type: 'number',
default: 5000,
optional: true
},
{
label: 'Enhanced Schema',
name: 'enhancedSchema',
type: 'boolean',
default: false,
optional: true
}
]
}
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const database = nodeData.inputs?.database as string
const timeoutMs = nodeData.inputs?.timeoutMs as number
const enhancedSchema = nodeData.inputs?.enhancedSchema as boolean
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const neo4jConfig = {
url: credentialData?.url,
username: credentialData?.username,
password: credentialData?.password
}
const neo4jGraph = await Neo4jGraph.initialize({
...neo4jConfig,
...(database && { database }),
...(timeoutMs && { timeoutMs }),
...(enhancedSchema && { enhancedSchema })
})
return neo4jGraph
}
}
module.exports = { nodeClass: Neo4j_Graphs }
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 677.5 242.4" style="enable-background:new 0 0 677.5 242.4;" xml:space="preserve"> <style type="text/css"> .st0{fill:#231F20;} .st1{fill:#014063;} </style> <g> <path class="st0" d="M137.8,61.9c-35.3,0-58.9,20.5-58.9,60.4v28.4c3.5-1.7,7.3-2.6,11.4-2.6s8,1,11.5,2.7v-28.5 c0-25.8,14.2-39.1,36-39.1s36,13.3,36,39.1v62.1h22.9v-62.1C196.7,82.2,173,61.9,137.8,61.9L137.8,61.9z"></path> <path class="st0" d="M209.2,124.7c0-36.2,26.6-62.8,64.2-62.8s63.8,26.6,63.8,62.8v8.5H233.3c3.4,21.3,19.3,33.1,40.1,33.1 c15.5,0,26.3-4.8,33.3-15.2h25.4c-9.2,22.2-30.9,36.5-58.7,36.5C235.7,187.5,209.2,161,209.2,124.7L209.2,124.7z M313,112.7 c-4.6-19.1-20.3-29.5-39.6-29.5s-34.8,10.6-39.4,29.5H313z"></path> <path class="st0" d="M349.5,124.7c0-36.2,26.6-62.8,64.2-62.8s64.2,26.6,64.2,62.8c0,36.2-26.6,62.8-64.2,62.8 S349.5,161,349.5,124.7z M454.7,124.7c0-24.2-16.4-41.5-41.1-41.5s-41.1,17.4-41.1,41.5c0,24.1,16.4,41.5,41.1,41.5 S454.7,148.9,454.7,124.7z"></path> <path class="st0" d="M609.1,208.1h2.7c14.7,0,20.3-6.5,20.3-23.4V65.9H655v117.3c0,29.5-11.6,44.7-41.1,44.7h-4.8L609.1,208.1 L609.1,208.1z"></path> <path class="st0" d="M597.6,195.9h-22.9v-28.3h-58.2c-11.6,0-21.7-5.7-26.3-14.8c-4.3-8.6-3.1-18.7,3.1-27.2L545.6,57 c7.5-10.1,20.2-14.2,32.2-10.2c12,4,19.8,14.7,19.8,27.3v73.1h17.2v20.4h-17.2V195.9L597.6,195.9z M512.6,138.1 c-0.7,0.9-1.1,2.1-1.1,3.4c0,3.2,2.6,5.8,5.8,5.8h57.5V73.6c0-3.8-2.8-5.2-4-5.6c-0.5-0.1-1.2-0.3-2.1-0.3c-1.4,0-3.1,0.5-4.6,2.4 L512.6,138.1L512.6,138.1L512.6,138.1z"></path> <path class="st1" d="M24.6,125.8c-3,1.5-5.8,4-7.8,7.3c-2,3.3-2.8,6.8-2.5,10.3c0.3,6.3,3.8,12.1,9.5,15.3c5.3,3,11.3,2.3,17,1 c7-1.8,13-2.5,19.3,1.3c0,0,0,0,0.3,0c10.8,6.3,10.8,22.1,0,28.4c0,0,0,0-0.3,0c-6.3,3.8-12.3,3-19.3,1.3c-5.5-1.5-11.5-2.3-17,1 c-5.8,3.3-9,9.3-9.5,15.3c-0.3,3.5,0.5,7,2.5,10.3c2,3.3,4.5,5.8,7.8,7.3c5.5,2.8,12.3,2.8,18-0.5c5.3-3,7.8-8.8,9.3-14.3 c2-7,4.3-12.6,10.8-16.1c6.3-3.8,12.3-3,19.3-1.3c5.5,1.5,11.5,2.3,17-1c5.8-3.3,9-9.3,9.5-15.3c0-0.5,0-0.8,0-1.3 c0-0.5,0-0.8,0-1.3c-0.3-6.3-3.8-12.1-9.5-15.3c-5.3-3-11.3-2.3-17-1c-7,1.8-13,2.5-19.3-1.3c-6.3-3.8-8.8-9.1-10.8-16.1 c-1.5-5.5-4-11.1-9.3-14.3C36.8,123.1,30.1,123.1,24.6,125.8z"></path> <path class="st1" d="M643.6,17.2c-10.8,0-19.6,8.8-19.6,19.6s8.8,19.6,19.6,19.6c10.8,0,19.6-8.8,19.6-19.6S654.4,17.2,643.6,17.2z "></path> </g> </svg>

After

Width:  |  Height:  |  Size: 2.4 KiB