@smythos/sre 1.5.36 → 1.5.37
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.
package/package.json
CHANGED
|
@@ -29,6 +29,8 @@ export class DataSourceLookup extends Component {
|
|
|
29
29
|
// Need to reserve 30 characters for the prefixed unique id
|
|
30
30
|
'string.max': `The length of the 'namespace' name must be 50 characters or fewer.`,
|
|
31
31
|
}),
|
|
32
|
+
scoreThreshold: Joi.number().optional().label('Score Threshold'),
|
|
33
|
+
includeScore: Joi.boolean().optional().label('Include Score'),
|
|
32
34
|
});
|
|
33
35
|
constructor() {
|
|
34
36
|
super();
|
|
@@ -53,6 +55,9 @@ export class DataSourceLookup extends Component {
|
|
|
53
55
|
const postprocess = config.data?.postprocess || false;
|
|
54
56
|
const includeMetadata = config.data?.includeMetadata || false;
|
|
55
57
|
|
|
58
|
+
const scoreThreshold = config.data?.scoreThreshold || 0.001; // Use low score (0.001) to return most results for backward compatibility
|
|
59
|
+
const includeScore = config.data?.includeScore || false;
|
|
60
|
+
|
|
56
61
|
const _input = typeof input.Query === 'string' ? input.Query : JSON.stringify(input.Query);
|
|
57
62
|
|
|
58
63
|
const topK = Math.max(config.data?.topK || 50, 50);
|
|
@@ -64,27 +69,40 @@ export class DataSourceLookup extends Component {
|
|
|
64
69
|
throw new Error(`Namespace ${namespace} does not exist`);
|
|
65
70
|
}
|
|
66
71
|
|
|
67
|
-
let results: string[] | { content: string; metadata: any }[];
|
|
72
|
+
let results: string[] | { content: string; metadata: any; score?: number }[];
|
|
68
73
|
let _error;
|
|
69
74
|
try {
|
|
70
75
|
const response = await vectorDbConnector
|
|
71
76
|
.requester(AccessCandidate.team(teamId))
|
|
72
77
|
.search(namespace, _input, { topK, includeMetadata: true });
|
|
78
|
+
|
|
73
79
|
results = response.slice(0, config.data.topK).map((result) => ({
|
|
74
80
|
content: result.text,
|
|
75
81
|
metadata: result.metadata,
|
|
82
|
+
score: result.score, // use a very low score to return
|
|
76
83
|
}));
|
|
77
84
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
results = results.filter((result) => result.score >= scoreThreshold);
|
|
86
|
+
|
|
87
|
+
// Transform results based on inclusion flags
|
|
88
|
+
results = results.map((result) => {
|
|
89
|
+
const transformedResult: any = {
|
|
81
90
|
content: result.content,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (includeMetadata) {
|
|
94
|
+
// legacy user-specific metadata key [result.metadata?.metadata]
|
|
95
|
+
transformedResult.metadata = this.parseMetadata(result.metadata || result.metadata?.metadata);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (includeScore) {
|
|
99
|
+
transformedResult.score = result.score;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// If neither metadata nor score is included, return just the content string
|
|
103
|
+
return includeMetadata || includeScore ? transformedResult : result.content;
|
|
104
|
+
});
|
|
105
|
+
|
|
88
106
|
debugOutput += `[Results] \nLoaded ${results.length} results from namespace: ${namespace}\n\n`;
|
|
89
107
|
} catch (error) {
|
|
90
108
|
_error = error.toString();
|
|
@@ -112,6 +130,7 @@ export class DataSourceLookup extends Component {
|
|
|
112
130
|
|
|
113
131
|
const totalLength = JSON.stringify(results).length;
|
|
114
132
|
debugOutput += `[Total Length] \n${totalLength}\n\n`;
|
|
133
|
+
|
|
115
134
|
return {
|
|
116
135
|
Results: results,
|
|
117
136
|
_error,
|
|
@@ -4,6 +4,7 @@ import Joi from 'joi';
|
|
|
4
4
|
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
5
5
|
import { AWSCredentials, AWSRegionConfig } from '@sre/types/AWS.types';
|
|
6
6
|
import { calculateExecutionCost, generateCodeFromLegacyComponent, getLambdaCredentials, reportUsage } from '@sre/helpers/AWSLambdaCode.helper';
|
|
7
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
7
8
|
|
|
8
9
|
export class ServerlessCode extends Component {
|
|
9
10
|
|
|
@@ -96,7 +97,7 @@ export class ServerlessCode extends Component {
|
|
|
96
97
|
const cost = calculateExecutionCost(executionTime);
|
|
97
98
|
if (!codeCredentials.isUserProvidedKeys) {
|
|
98
99
|
const accountConnector = ConnectorService.getAccountConnector();
|
|
99
|
-
const agentTeam = await accountConnector.getCandidateTeam(agent.id);
|
|
100
|
+
const agentTeam = await accountConnector.getCandidateTeam(AccessCandidate.agent(agent.id));
|
|
100
101
|
reportUsage({ cost, agentId: agent.id, teamId: agentTeam });
|
|
101
102
|
}
|
|
102
103
|
|