Changing distance metrics
By default, Pinecone indexes using the cosine similarity distance metric to compute similarity scores between vectors, which are used when querying to find the most similar vectors. Pinecone also supports other distance metrics, including Euclidean distance and the dot product.
The distance metric is set when the index is created, and can't be changed afterwards. In this exercise, you'll practice creating an index that uses the dot product distance metric.
This exercise is part of the course
Vector Databases for Embeddings with Pinecone
Exercise instructions
- Initialize the Pinecone connection with your API key.
- Create a new index called
"dotproduct-index"
that uses the dot product distance metric. - List your indexes to verify that it has been created and has the correct metric.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Initialize the Pinecone client with your API key
pc = Pinecone(api_key="____")
# Create an index that uses the dot product distance metric
pc.create_index(
name="____",
dimension=1536,
____,
spec=ServerlessSpec(
cloud='aws',
region='us-east-1'
)
)
# Print a list of your indexes
print(____)