-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-pinecone.js
More file actions
58 lines (46 loc) · 1.73 KB
/
test-pinecone.js
File metadata and controls
58 lines (46 loc) · 1.73 KB
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
const { Pinecone } = require('@pinecone-database/pinecone');
// Configuration for your Pinecone index
const config = {
apiKey: 'pcsk_52AbGy_CDjDs6zTiABmKYor3xnxxh6qkYQFQEwsNmg9XCQwprpfv4NCWmk6TDnJ3jTECE4',
indexName: 'code-embedddings',
environment: 'us-east-1',
host: 'https://code-embedddings-r7rx8or.svc.aped-4627-b74a.pinecone.io'
};
async function testPinecone() {
try {
console.log('Initializing Pinecone client...');
// Log the Pinecone module structure
const pineconeModule = require('@pinecone-database/pinecone');
console.log('Pinecone module exports:', Object.keys(pineconeModule));
// Try with the latest API
console.log('Creating Pinecone instance...');
const pc = new pineconeModule.Pinecone({
apiKey: config.apiKey
});
console.log('Listing indexes...');
const indexes = await pc.listIndexes();
console.log('Available indexes:', indexes);
console.log('Getting index...');
const index = pc.index(config.indexName);
console.log('Describing index statistics...');
const stats = await index.describeIndexStats();
console.log('Index statistics:', stats);
console.log('Connection successful!');
// Test query (empty vector with correct dimensions)
console.log('Testing query with empty vector...');
const queryResult = await index.query({
vector: Array(768).fill(0),
topK: 1,
includeMetadata: true
});
console.log('Query result:', queryResult);
} catch (error) {
console.error('Error connecting to Pinecone:', error);
console.error('Error details:', error.message);
if (error.stack) {
console.error('Stack trace:', error.stack);
}
}
}
// Run the test
testPinecone();