Hi Jesse,
I really need your help.
Idon’t see how I can attach a file, so I just paste it here:
The node-js script:
import fetch from ‘node-fetch’;
global.fetch = fetch;
import { Pinecone } from ‘@pinecone-database/pinecone’;
const pc = new Pinecone({
apiKey: ‘XXX’,
fetchApi: fetch // Pass fetch implementation here
});
const indexName = ‘firsttest’;
console.log(‘1’);
const existingIndexes = await pc.listIndexes();
console.log(existingIndexes.indexes);
let found=existingIndexes.indexes.find(o => o.name == indexName);
console.log('found: ',found);
if (!found)
{
await pc.createIndex({
name: indexName,
dimension: 1024, // Replace with your model dimensions
metric: ‘cosine’, // Replace with your model metric
spec: {
serverless: {
cloud: ‘aws’,
region: ‘us-east-1’
}
}
});
console.log(Index '${indexName}' created successfully.
);
} else {
console.log(Index '${indexName}' already exists.
);
}
console.log(‘2’);
const model = ‘multilingual-e5-large’;
const data = [
{ id: ‘vec1’, text: ‘Apple is a popular fruit known for its sweetness and crisp texture.’ },
{ id: ‘vec2’, text: ‘The tech company Apple is known for its innovative products like the iPhone.’ },
{ id: ‘vec3’, text: ‘Many people enjoy eating apples as a healthy snack.’ },
{ id: ‘vec4’, text: ‘Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces.’ },
{ id: ‘vec5’, text: ‘An apple a day keeps the doctor away, as the saying goes.’ },
{ id: ‘vec6’, text: ‘Apple Computer Company was founded on April 1, 1976, by Steve Jobs, Steve Wozniak, and Ronald Wayne as a partnership.’ }
];
console.log(‘3’);
try {
const embeddings = pc.inference.embed(
model,
data.map(d => d.text),
{ inputType: ‘passage’, truncate: ‘END’ }
);
console.log(‘Embeddings generated successfully:’, embeddings);
} catch (error) {
console.error(‘Error during embeddings generation:’, error);
}
console.log(‘4’);
console.log(embeddings[0]);
console.log(‘5’);
const index = pc.index(indexName);
const vectors = data.map((d, i) => ({
id: d.id,
values: embeddings[i].values,
metadata: { text: d.text }
}));
console.log(‘6’);
await index.namespace(‘ns1’).upsert(vectors);
const stats = await index.describeIndexStats();
console.log(‘7’);
console.log(stats)