Skip to content

Commit a6d3e11

Browse files
authored
Merge pull request FlowiseAI#774 from vectara/sentence-config
Add sentence config option to Vectara
2 parents 0c79791 + ca4f3bd commit a6d3e11

File tree

4 files changed

+248
-196
lines changed

4 files changed

+248
-196
lines changed

packages/components/nodes/vectorstores/Vectara_Existing/Vectara_Existing.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
22
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
3-
import { VectaraStore, VectaraLibArgs, VectaraFilter } from 'langchain/vectorstores/vectara'
3+
import { VectaraStore, VectaraLibArgs, VectaraFilter, VectaraContextConfig } from 'langchain/vectorstores/vectara'
44

55
class VectaraExisting_VectorStores implements INode {
66
label: string
@@ -40,9 +40,27 @@ class VectaraExisting_VectorStores implements INode {
4040
additionalParams: true,
4141
optional: true
4242
},
43+
{
44+
label: 'Sentences Before',
45+
name: 'sentencesBefore',
46+
description: 'Number of sentences to fetch before the matched sentence. Defaults to 2.',
47+
type: 'number',
48+
additionalParams: true,
49+
optional: true
50+
},
51+
{
52+
label: 'Sentences After',
53+
name: 'sentencesAfter',
54+
description: 'Number of sentences to fetch after the matched sentence. Defaults to 2.',
55+
type: 'number',
56+
additionalParams: true,
57+
optional: true
58+
},
4359
{
4460
label: 'Lambda',
4561
name: 'lambda',
62+
description:
63+
'Improves retrieval accuracy by adjusting the balance (from 0 to 1) between neural search and keyword-based search factors.',
4664
type: 'number',
4765
additionalParams: true,
4866
optional: true
@@ -77,6 +95,8 @@ class VectaraExisting_VectorStores implements INode {
7795
const corpusId = getCredentialParam('corpusID', credentialData, nodeData)
7896

7997
const vectaraMetadataFilter = nodeData.inputs?.filter as string
98+
const sentencesBefore = nodeData.inputs?.sentencesBefore as number
99+
const sentencesAfter = nodeData.inputs?.sentencesAfter as number
80100
const lambda = nodeData.inputs?.lambda as number
81101
const output = nodeData.outputs?.output as string
82102
const topK = nodeData.inputs?.topK as string
@@ -92,6 +112,11 @@ class VectaraExisting_VectorStores implements INode {
92112
if (vectaraMetadataFilter) vectaraFilter.filter = vectaraMetadataFilter
93113
if (lambda) vectaraFilter.lambda = lambda
94114

115+
const vectaraContextConfig: VectaraContextConfig = {}
116+
if (sentencesBefore) vectaraContextConfig.sentencesBefore = sentencesBefore
117+
if (sentencesAfter) vectaraContextConfig.sentencesAfter = sentencesAfter
118+
vectaraFilter.contextConfig = vectaraContextConfig
119+
95120
const vectorStore = new VectaraStore(vectaraArgs)
96121

97122
if (output === 'retriever') {

packages/components/nodes/vectorstores/Vectara_Upsert/Vectara_Upsert.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
22
import { Embeddings } from 'langchain/embeddings/base'
33
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
4-
import { VectaraStore, VectaraLibArgs, VectaraFilter } from 'langchain/vectorstores/vectara'
4+
import { VectaraStore, VectaraLibArgs, VectaraFilter, VectaraContextConfig } from 'langchain/vectorstores/vectara'
55
import { Document } from 'langchain/document'
66
import { flatten } from 'lodash'
77

@@ -49,9 +49,27 @@ class VectaraUpsert_VectorStores implements INode {
4949
additionalParams: true,
5050
optional: true
5151
},
52+
{
53+
label: 'Sentences Before',
54+
name: 'sentencesBefore',
55+
description: 'Number of sentences to fetch before the matched sentence. Defaults to 2.',
56+
type: 'number',
57+
additionalParams: true,
58+
optional: true
59+
},
60+
{
61+
label: 'Sentences After',
62+
name: 'sentencesAfter',
63+
description: 'Number of sentences to fetch after the matched sentence. Defaults to 2.',
64+
type: 'number',
65+
additionalParams: true,
66+
optional: true
67+
},
5268
{
5369
label: 'Lambda',
5470
name: 'lambda',
71+
description:
72+
'Improves retrieval accuracy by adjusting the balance (from 0 to 1) between neural search and keyword-based search factors.',
5573
type: 'number',
5674
additionalParams: true,
5775
optional: true
@@ -88,6 +106,8 @@ class VectaraUpsert_VectorStores implements INode {
88106
const docs = nodeData.inputs?.document as Document[]
89107
const embeddings = {} as Embeddings
90108
const vectaraMetadataFilter = nodeData.inputs?.filter as string
109+
const sentencesBefore = nodeData.inputs?.sentencesBefore as number
110+
const sentencesAfter = nodeData.inputs?.sentencesAfter as number
91111
const lambda = nodeData.inputs?.lambda as number
92112
const output = nodeData.outputs?.output as string
93113
const topK = nodeData.inputs?.topK as string
@@ -103,6 +123,11 @@ class VectaraUpsert_VectorStores implements INode {
103123
if (vectaraMetadataFilter) vectaraFilter.filter = vectaraMetadataFilter
104124
if (lambda) vectaraFilter.lambda = lambda
105125

126+
const vectaraContextConfig: VectaraContextConfig = {}
127+
if (sentencesBefore) vectaraContextConfig.sentencesBefore = sentencesBefore
128+
if (sentencesAfter) vectaraContextConfig.sentencesAfter = sentencesAfter
129+
vectaraFilter.contextConfig = vectaraContextConfig
130+
106131
const flattenDocs = docs && docs.length ? flatten(docs) : []
107132
const finalDocs = []
108133
for (let i = 0; i < flattenDocs.length; i += 1) {

packages/components/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"google-auth-library": "^9.0.0",
4141
"graphql": "^16.6.0",
4242
"html-to-text": "^9.0.5",
43-
"langchain": "^0.0.122",
43+
"langchain": "^0.0.126",
4444
"linkifyjs": "^4.1.1",
4545
"mammoth": "^1.5.1",
4646
"moment": "^2.29.3",

0 commit comments

Comments
 (0)