forked from developersdigest/langchain-pinecone-101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-createPineconeIndex.js
30 lines (30 loc) · 928 Bytes
/
1-createPineconeIndex.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
export const createPineconeIndex = async (
client,
indexName,
vectorDimension
) => {
// 1. Initiate index existence check
console.log(`Checking "${indexName}"...`);
// 2. Get list of existing indexes
const existingIndexes = await client.listIndexes();
// 3. If index doesn't exist, create it
if (!existingIndexes.includes(indexName)) {
// 4. Log index creation initiation
console.log(`Creating "${indexName}"...`);
// 5. Create index
const createClient = await client.createIndex({
createRequest: {
name: indexName,
dimension: vectorDimension,
metric: "cosine",
},
});
// 6. Log successful creation
console.log(`Created with client:`, createClient);
// 7. Wait 60 seconds for index initialization
await new Promise((resolve) => setTimeout(resolve, 60000));
} else {
// 8. Log if index already exists
console.log(`"${indexName}" already exists.`);
}
};