/
vector-search-result.test.js
97 lines (88 loc) · 2.04 KB
/
vector-search-result.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const tap = require('tap')
const LangChainVectorSearchResult = require('../../../../lib/llm-events/langchain/vector-search-result')
const LangChainVectorSearch = require('../../../../lib/llm-events/langchain/vector-search')
tap.beforeEach((t) => {
t.context._tx = {
trace: {
custom: {
get() {
return {
'llm.conversation_id': 'test-conversation'
}
}
}
}
}
t.context.agent = {
config: {
ai_monitoring: {
record_content: {
enabled: true
}
},
applications() {
return ['test-app']
}
},
tracer: {
getTransaction() {
return t.context._tx
}
}
}
t.context.segment = {
id: 'segment-1',
transaction: {
id: 'tx-1',
traceId: 'trace-1'
},
getDurationInMillis() {
return 42
}
}
t.context.runId = 'run-1'
t.context.metadata = { foo: 'foo' }
})
tap.test('create entity', async (t) => {
const search = new LangChainVectorSearch({
...t.context,
query: 'hello world',
k: 1
})
const searchResult = new LangChainVectorSearchResult({
...t.context,
sequence: 1,
pageContent: 'hello world',
search_id: search.id
})
t.match(searchResult, {
id: /[a-z0-9-]{36}/,
appName: 'test-app',
['llm.conversation_id']: 'test-conversation',
request_id: 'run-1',
span_id: 'segment-1',
transaction_id: 'tx-1',
trace_id: 'trace-1',
['metadata.foo']: 'foo',
ingest_source: 'Node',
vendor: 'langchain',
virtual_llm: true,
sequence: 1,
page_content: 'hello world',
search_id: search.id
})
})
tap.test('respects record_content setting', async (t) => {
t.context.agent.config.ai_monitoring.record_content.enabled = false
const search = new LangChainVectorSearchResult({
...t.context,
sequence: 1,
pageContent: 'hello world'
})
t.equal(search.page_content, undefined)
})