Skip to main content

snippets_py

Integration

New integration from credential
pineconeClient = yepcode.integration.pinecone('credential-slug')
New integration from plain authentication data
from pinecone import Pinecone

pineconeClient = Pinecone(api_key="YOUR_API_KEY")

Create Index

Creates an index
pineconeClient.create_index(name="example-index", dimension=1024)

List Indexes

List indexes in your current project
active_indexes = pineconeClient.list_indexes()

Construct an Index Object

Construct an index objet with an existing index name
index = pineconeClient.Index("example-index");

Describe Index

Describes an index
index_description = pineconeClient.describe_index("example-index")

Delete Index

Deletes an index
pineconeClient.delete_index("example-index")

Scale Replicas

Sets the number of replicas and pod type for an index
new_number_of_replicas = 4
pineconeClient.configure_index("example-index", replicas=new_number_of_replicas)

Upsert Vectors

Upserts vector to an index
index = pineconeClient.Index("example-index")

upsert_response = index.upsert(
vectors=[
(
"vec1", # Vector ID
[0.1, 0.2, 0.3, 0.4], # Dense vector values
{"genre": "drama"} # Vector metadata
),
(
"vec2",
[0.2, 0.3, 0.4, 0.5],
{"genre": "action"}
)
],
namespace="example-namespace"
)

Query an Index

Queries an index filtering
index = pineconeClient.Index("example-index")

query_response = index.query(
namespace="example-namespace",
top_k=10,
include_values=True,
include_metadata=True,
vector=[0.1, 0.2, 0.3, 0.4],
filter={
"genre": {"$in": ["comedy", "documentary", "drama"]}
}
)

Update Vector

Updates a vector
index = pineconeClient.Index("example-index")

update_response = index.update(
id="vec1",
values=[0.1, 0.2, 0.3, 0.4],
set_metadata={"genre": "drama"},
namespace="example-namespace"
)

Delete Vector

Deletes a vector
index = pineconeClient.Index("example-index")

delete_response = index.delete(ids=["vec1", "vec2"], namespace="example-namespace")

Create Collection

Creates a collection from an index
pineconeClient.create_collection(
name="example-collection",
source="example-index"
)

List Collections

List the collections from in the current project
active_collections = pineconeClient.list_collections()

Describe Collection

Returns a description of one collection
collection_description = pineconeClient.describe_collection("example-collection")

Delete Collection

Delete a collection
pineconeClient.delete_collection("example-collection")