The getting started sample

I run the getting started sample.
Both in node-js and in Python.
When I get to the point where I try to load the vectors (the sentences)

const embeddings = await pc.inference.embed(
  model,
  data.map(d => d.text),
  { inputType: 'passage', truncate: 'END' }
);

It just exit the execution without any log (no error).

Hi @shlomo1. I just ran through the Python version of the database quickstart and found one issue: The time module needs to be imported. I’ll fix that soon.

from pinecone.grpc import PineconeGRPC as Pinecone
from pinecone import ServerlessSpec
import time

But with that import in place, the code works for me. Can you share the Python code you’re using?

I’ll test the Node.js example soon as well.

Best,
Jesse

@shlomo1, I just ran through the Node.js version of the database quickstart as well and didn’t have any issues. Are you using the exact code in the quickstart? If not, can you share the code you’re using?

Thanks Jesse,

I don’t have the Python code here.
I will send it tonight.

Hi Jesse,
I tried to run the Python script, but it failed with errors.
I attached it.
Did you have any access with the node-js script?
I don’t know how to continue.

(Attachment upsert_data.py is missing)

Sorry for my delay, @shlomo1. The attachment didn’t come through. Can you try again?

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)

Hi Jesse,

I sent you the code in my previous email.
Have you looked at it?
The problem is that it just doesn’t reach: console.log(4)
And doesn’t produce any error, just exit.

Sorry for the delay, @shlomo1. I’ve replicated what you’re seeing. I’ll look into this more this morning and get back to you.

@shlomo1, I believe I found the issue. All the Node SDK operations should return promises which are awaitable / asynchronous. So you need to change this:

const embeddings = pc.inference.embed(
    model,
    data.map(d => d.text),
    { inputType: 'passage', truncate: 'END' }
);

to this:

const embeddings = await pc.inference.embed(
    model,
    data.map(d => d.text),
    { inputType: 'passage', truncate: 'END' }
);

Give that a try and let me know.

Best,
Jesse

No, it didn’t work.
I added the: await
the first time I tried it I received and error:
Index ‘firsttest’ already exists.
So I changed it to: ‘secondtest’
Now it just didn’t return from the function as before.

I’m sorry for the delay, Schlomo. I’ve been away for the holiday here. I will look into this again first thing tomorrow. I tested the node quickstart, and it works in my end, but I’ll look at your code again.

Best,
Jesse

Thank you very much.

Hi @shlomo1. There were a few syntax issues in your code. Here’s a version that that works for me.

Note that I’m using an imported function to wait 10 seconds after upserting records, before requesting stats from the index, as there is a slight delay before records can be accessed. Also, I’ve removed your node-fetch import.

Please give this a try.

import { Pinecone } from '@pinecone-database/pinecone';
import { setTimeout } from "timers/promises";

const pc = new Pinecone({ apiKey: 'YOUR_API_KEY' });

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 %s created successfully.', indexName);
    } else {
    console.log('Index %s already exists.', indexName);
    }
    
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');

const embeddings = await pc.inference.embed(
    model,
    data.map(d => d.text),
    { inputType: 'passage', truncate: 'END' }
);

try {
    const embeddings = await 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);

await setTimeout(10000);
console.log("Waited 5s");

const stats = await index.describeIndexStats();

console.log('7');

console.log(stats);

Hi Jesse,

Thank you very much.
I tested it and it still has the same problem.
But, then I changed the ‘indexName’
So it will not find my previous indexes and create a new one.
Nw I receive the following error:
found: undefined
C:\wamp64\www\props\pine-node\node_modules@pinecone-database\pinecone\dist\errors\http.js:183
return new PineconeBadRequestError(failedRequestInfo);
^
PineconeBadRequestError: {“error”:{“code”:“FORBIDDEN”,“message”:“Request failed. You’ve reached the max serverless indexes allowed in project Default (5). To add more serverless indexes, upgrade your plan.”},“status”:403}

But I don’t want to upgrade the plan before I know that it works OK for me.
And that I could test it properly with my real database.

Hi @shlomo1. Yes, there is a limit of 5 serverless indexes on the Starter plan. To keep testing, simply delete one or more of your existing indexes to bring yourself under the limit.

So I managed to delete the index (I deleted 3 indexes).
But it still exit on the same finction:
const embeddings = await pc.inference.embed
without any message.
How is it that I have this error with the sample that they provide?
I am really frustrated, because on the simplest task I am not getting any progress!

Hi @shlomo1! Audrey from Pinecone here.

Just circling back to your original JS code snippet, I have a quick question: why are you using node-fetch? This might be a red herring, but I want to clarify so we can duplicate your setup on our end.

If you can also provide the following info, that’d be great:

  • The version of the Node SDK you are using
  • The version of Node you are using
  • Your operating system

Hi Aurey,
Thanks for your willing to help me.

  1. I added the fetch lines bcause without it, node returned an error (see) at the bottom.
  2. node version: v14.15.0
  3. Microsoft Windows [Version 10.0.22631.4460]
    The error:
    C:\wamp64\www\props\pine-node\node_modules@pinecone-database\pinecone\dist\utils\fetch.js:19
    throw new errors_1.PineconeConfigurationError(‘No global or user-provided fetch implementations found. Please supply a fetch implementation.’);
    ^

Ah, there it is. So, our Node SDK (noted here) only supports Node versions 18+. Are you comfortable upgrading your Node version? Happy to walk you through it if you need!