CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Vector Databases for Embeddings with Pinecone

Afficher le cours

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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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(____)
Modifier et exécuter le code