1
1
import { ICommonObject , INode , INodeData , INodeOutputsValue , INodeParams } from '../../../src/Interface'
2
2
import { Embeddings } from 'langchain/embeddings/base'
3
3
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'
5
5
import { Document } from 'langchain/document'
6
6
import { flatten } from 'lodash'
7
7
@@ -49,9 +49,27 @@ class VectaraUpsert_VectorStores implements INode {
49
49
additionalParams : true ,
50
50
optional : true
51
51
} ,
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
+ } ,
52
68
{
53
69
label : 'Lambda' ,
54
70
name : 'lambda' ,
71
+ description :
72
+ 'Improves retrieval accuracy by adjusting the balance (from 0 to 1) between neural search and keyword-based search factors.' ,
55
73
type : 'number' ,
56
74
additionalParams : true ,
57
75
optional : true
@@ -88,6 +106,8 @@ class VectaraUpsert_VectorStores implements INode {
88
106
const docs = nodeData . inputs ?. document as Document [ ]
89
107
const embeddings = { } as Embeddings
90
108
const vectaraMetadataFilter = nodeData . inputs ?. filter as string
109
+ const sentencesBefore = nodeData . inputs ?. sentencesBefore as number
110
+ const sentencesAfter = nodeData . inputs ?. sentencesAfter as number
91
111
const lambda = nodeData . inputs ?. lambda as number
92
112
const output = nodeData . outputs ?. output as string
93
113
const topK = nodeData . inputs ?. topK as string
@@ -103,6 +123,11 @@ class VectaraUpsert_VectorStores implements INode {
103
123
if ( vectaraMetadataFilter ) vectaraFilter . filter = vectaraMetadataFilter
104
124
if ( lambda ) vectaraFilter . lambda = lambda
105
125
126
+ const vectaraContextConfig : VectaraContextConfig = { }
127
+ if ( sentencesBefore ) vectaraContextConfig . sentencesBefore = sentencesBefore
128
+ if ( sentencesAfter ) vectaraContextConfig . sentencesAfter = sentencesAfter
129
+ vectaraFilter . contextConfig = vectaraContextConfig
130
+
106
131
const flattenDocs = docs && docs . length ? flatten ( docs ) : [ ]
107
132
const finalDocs = [ ]
108
133
for ( let i = 0 ; i < flattenDocs . length ; i += 1 ) {
0 commit comments