mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
add vector to prompt
This commit is contained in:
+87
@@ -0,0 +1,87 @@
|
||||
import { VectorStore } from 'langchain/vectorstores/base'
|
||||
import { INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
|
||||
import { handleEscapeCharacters } from '../../../src/utils'
|
||||
|
||||
class VectorStoreToDocument_DocumentLoaders implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
description: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
inputs: INodeParams[]
|
||||
outputs: INodeOutputsValue[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'VectorStore To Document'
|
||||
this.name = 'vectorStoreToDocument'
|
||||
this.version = 1.0
|
||||
this.type = 'Document'
|
||||
this.icon = 'vectorretriever.svg'
|
||||
this.category = 'Document Loaders'
|
||||
this.description = 'Search documents with scores from vector store'
|
||||
this.baseClasses = [this.type]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Vector Store',
|
||||
name: 'vectorStore',
|
||||
type: 'VectorStore'
|
||||
},
|
||||
{
|
||||
label: 'Minimum Score (%)',
|
||||
name: 'minScore',
|
||||
type: 'number',
|
||||
optional: true,
|
||||
placeholder: '75',
|
||||
step: 1,
|
||||
description: 'Minumum score for embeddings documents to be included'
|
||||
}
|
||||
]
|
||||
this.outputs = [
|
||||
{
|
||||
label: 'Document',
|
||||
name: 'document',
|
||||
baseClasses: this.baseClasses
|
||||
},
|
||||
{
|
||||
label: 'Text',
|
||||
name: 'text',
|
||||
baseClasses: ['string', 'json']
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, input: string): Promise<any> {
|
||||
const vectorStore = nodeData.inputs?.vectorStore as VectorStore
|
||||
const minScore = nodeData.inputs?.minScore as number
|
||||
const output = nodeData.outputs?.output as string
|
||||
|
||||
const topK = (vectorStore as any)?.k ?? 4
|
||||
|
||||
const docs = await vectorStore.similaritySearchWithScore(input, topK)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('\x1b[94m\x1b[1m\n*****VectorStore Documents*****\n\x1b[0m\x1b[0m')
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(docs)
|
||||
|
||||
if (output === 'document') {
|
||||
let finaldocs = []
|
||||
for (const doc of docs) {
|
||||
if (minScore && doc[1] < minScore / 100) continue
|
||||
finaldocs.push(doc[0])
|
||||
}
|
||||
return finaldocs
|
||||
} else {
|
||||
let finaltext = ''
|
||||
for (const doc of docs) {
|
||||
if (minScore && doc[1] < minScore / 100) continue
|
||||
finaltext += `${doc[0].pageContent}\n`
|
||||
}
|
||||
return handleEscapeCharacters(finaltext, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: VectorStoreToDocument_DocumentLoaders }
|
||||
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-file-database" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<path d="M12 12.75m-4 0a4 1.75 0 1 0 8 0a4 1.75 0 1 0 -8 0"></path>
|
||||
<path d="M8 12.5v3.75c0 .966 1.79 1.75 4 1.75s4 -.784 4 -1.75v-3.75"></path>
|
||||
<path d="M14 3v4a1 1 0 0 0 1 1h4"></path>
|
||||
<path d="M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 588 B |
Reference in New Issue
Block a user