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
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 length1536
, returning a singleTrue
orFalse
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))