forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinecone_v0.test.ts
129 lines (121 loc) · 3.17 KB
/
pinecone_v0.test.ts
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { describe, it, vi, expect, beforeEach } from 'vitest';
import { getDataset } from './test/mocks/dataset';
describe('PineconeNode class', () => {
let node;
let inputData;
let dataset;
const timeout = 60000;
beforeEach(() => {
vi.mock('@pinecone-database/pinecone', () => ({
Pinecone: vi.fn().mockImplementation(() => ({
deleteIndex: vi.fn().mockResolvedValue({}),
describeIndex: vi.fn().mockRejectedValue(new Error('Index not found')),
createIndex: vi.fn().mockResolvedValue({}),
index: vi.fn().mockReturnValue({
namespace: vi.fn().mockReturnValue({
upsert: vi.fn().mockResolvedValue({}),
query: vi.fn().mockResolvedValue({
matches: [
{ id: 'claim1', score: 0.9 },
{ id: 'claim2', score: 0.8 }
]
})
})
}),
listIndexes: vi.fn().mockResolvedValue(['test-index'])
}))
}));
dataset = getDataset();
node = dataset.graph.findImpl('pinecone');
inputData = {
embeddings: [{ id: 'embedding1', values: [0.1, 0.2, 0.3] }],
pinecone_api_key: 'pinecone_api_key'
};
}, timeout);
it(
'should initialize Pinecone with the provided API key',
async () => {
await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null,
dataset
);
expect(node.pc).toBeDefined();
},
timeout
);
it(
'should create a new index if it does not exist and upsert embeddings',
async () => {
await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null,
dataset
);
expect(node.pc.createIndex).toHaveBeenCalled();
expect(node.pc.index().namespace('comments').upsert).toHaveBeenCalledWith(
inputData.embeddings
);
},
timeout
);
// Todo: this should be implemented with a mock embeddings node
// it(
// 'should query Pinecone index and return nearest neighbors',
// async () => {
// const term = 'test search term';
// const topK = 2;
// const results = await node.query_pinecone(term, topK, dataset);
// expect(results).toEqual([
// { claim: 'claim1', score: 0.9 },
// { claim: 'claim2', score: 0.8 }
// ]);
// },
// timeout
// );
it(
'should list Pinecone indexes',
async () => {
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null,
dataset
);
expect(output.indexes).toEqual(['test-index']);
},
timeout
);
it(
'should provide tools for querying Pinecone index',
async () => {
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null,
dataset
);
expect(output.tools).toBeDefined();
expect(output.tools[0].function.name).toBe('query_pinecone');
},
timeout
);
});