Get startedGet started for free

Checking dimensionality

You now have the know-how to begin ingesting vectors into a new Pinecone index! Before you jump in, you should check that your vectors are compatible with the dimensionality of your new index.

A list of dictionaries containing records to ingest has been provided as vectors. Here's a preview of its structure:

vectors = [
    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
        "metadata": {"genre": "action", "year": 2024}
    },
        ...,
]

If you accidentally create a valid index that doesn't meet the specifications detailed in the instructions, you'll need to add the following code before your .create_index() code:

pc.delete_index('datacamp-index')

This exercise is part of the course

Vector Databases for Embeddings with Pinecone

View Course

Exercise instructions

  • Initialize the Pinecone connection using your API key.
  • Create a new serverless Pinecone index called "datacamp-index"; leave the other settings as they are.
  • Use a list comprehension to check that each vector in vectors is length 1536, returning a single True or False indicating whether they all meet this condition.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Initialize the Pinecone client using your API key
pc = Pinecone(api_key="____")

# Create your Pinecone index
pc.____(
    name="____", 
    dimension=1536, 
    spec=____(
        cloud='aws', 
        region='us-east-1'
    )
)

# Check that each vector has a dimensionality of 1536
vector_dims = [____(vector['____']) == ____ for vector in ____]
print(____(vector_dims))
Edit and Run Code