Documentation ¶
Overview ¶
Package pinecone provides a client for the Pinecone managed vector database.
Index ¶
- func GenerateTestIndexName() string
- func WaitUntilIndexReady(ts *IntegrationTests, ctx context.Context) (bool, error)
- type Client
- func (c *Client) ConfigureIndex(ctx context.Context, name string, in ConfigureIndexParams) (*Index, error)
- func (c *Client) CreateCollection(ctx context.Context, in *CreateCollectionRequest) (*Collection, error)
- func (c *Client) CreatePodIndex(ctx context.Context, in *CreatePodIndexRequest) (*Index, error)
- func (c *Client) CreateServerlessIndex(ctx context.Context, in *CreateServerlessIndexRequest) (*Index, error)
- func (c *Client) DeleteCollection(ctx context.Context, collectionName string) error
- func (c *Client) DeleteIndex(ctx context.Context, idxName string) error
- func (c *Client) DescribeCollection(ctx context.Context, collectionName string) (*Collection, error)
- func (c *Client) DescribeIndex(ctx context.Context, idxName string) (*Index, error)
- func (c *Client) Index(in NewIndexConnParams, dialOpts ...grpc.DialOption) (*IndexConnection, error)
- func (c *Client) ListCollections(ctx context.Context) ([]*Collection, error)
- func (c *Client) ListIndexes(ctx context.Context) ([]*Index, error)
- type Cloud
- type Collection
- type CollectionStatus
- type ConfigureIndexParams
- type CreateCollectionRequest
- type CreatePodIndexRequest
- type CreateServerlessIndexRequest
- type DeletionProtection
- type DescribeIndexStatsResponse
- type EmbedParameters
- type EmbedRequest
- type FetchVectorsResponse
- type Index
- type IndexConnection
- func (idx *IndexConnection) Close() error
- func (idx *IndexConnection) DeleteAllVectorsInNamespace(ctx context.Context) error
- func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, metadataFilter *MetadataFilter) error
- func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) error
- func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIndexStatsResponse, error)
- func (idx *IndexConnection) DescribeIndexStatsFiltered(ctx context.Context, metadataFilter *MetadataFilter) (*DescribeIndexStatsResponse, error)
- func (idx *IndexConnection) FetchVectors(ctx context.Context, ids []string) (*FetchVectorsResponse, error)
- func (idx *IndexConnection) ListVectors(ctx context.Context, in *ListVectorsRequest) (*ListVectorsResponse, error)
- func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVectorIdRequest) (*QueryVectorsResponse, error)
- func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryByVectorValuesRequest) (*QueryVectorsResponse, error)
- func (idx *IndexConnection) UpdateVector(ctx context.Context, in *UpdateVectorRequest) error
- func (idx *IndexConnection) UpsertVectors(ctx context.Context, in []*Vector) (uint32, error)
- type IndexMetric
- type IndexSpec
- type IndexStatus
- type IndexStatusState
- type InferenceService
- type IntegrationTests
- type ListVectorsRequest
- type ListVectorsResponse
- type Metadata
- type MetadataFilter
- type NamespaceSummary
- type NewClientBaseParams
- type NewClientParams
- type NewIndexConnParams
- type PineconeError
- type PodSpec
- type PodSpecMetadataConfig
- type QueryByVectorIdRequest
- type QueryByVectorValuesRequest
- type QueryVectorsResponse
- type ScoredVector
- type ServerlessSpec
- type SparseValues
- type UpdateVectorRequest
- type Usage
- type Vector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WaitUntilIndexReady ¶ added in v1.1.0
func WaitUntilIndexReady(ts *IntegrationTests, ctx context.Context) (bool, error)
Types ¶
type Client ¶
type Client struct { Inference *InferenceService // contains filtered or unexported fields }
Client holds the parameters for connecting to the Pinecone service. It is returned by the NewClient and NewClientBase functions. To use Client, first build the parameters of the request using NewClientParams (or NewClientBaseParams). Then, pass those parameters into the NewClient (or NewClientBase) function to create a new Client object. Once instantiated, you can use Client to execute Pinecone API requests (e.g. create an Index, list Indexes, etc.), and Inference API requests. Read more about different Pinecone API routes at docs.pinecone.io/reference/api.
Note: Client methods are safe for concurrent use.
Fields:
- Inference: An InferenceService object that exposes methods for interacting with the Pinecone Inference API.
- headers: An optional map of HTTP headers to include in each API request, provided through NewClientParams.Headers or NewClientBaseParams.Headers.
- restClient: Optional underlying *http.Client object used to communicate with the Pinecone API, provided through NewClientParams.RestClient or NewClientBaseParams.RestClient. If not provided, a default client is created for you.
- sourceTag: An optional string used to help Pinecone attribute API activity, provided through NewClientParams.SourceTag or NewClientBaseParams.SourceTag.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) // --> This creates a new Client object. if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } else { fmt.Printf("Successfully found the \"%s\" index!\n", idx.Name) } idxConnection, err := pc.Index(idx.Host) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } else { log.Println("IndexConnection created successfully!") }
func NewClient ¶
func NewClient(in NewClientParams) (*Client, error)
NewClient creates and initializes a new instance of Client. This function sets up the Pinecone client with the necessary configuration for authentication and communication.
Parameters:
- in: A NewClientParams object. See NewClientParams for more information.
Note: It is important to handle the error returned by this function to ensure that the Pinecone client has been created successfully before attempting to make API calls.
Returns a pointer to an initialized Client instance or an error.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") }
func NewClientBase ¶ added in v0.5.0
func NewClientBase(in NewClientBaseParams) (*Client, error)
NewClientBase creates and initializes a new instance of Client with custom authentication headers.
Parameters:
- in: A NewClientBaseParams object that includes the necessary configuration for the Pinecone client. See NewClientBaseParams for more information.
Notes:
- It is important to handle the error returned by this function to ensure that the Pinecone client has been created successfully before attempting to make API calls.
- A Pinecone API key is not required when using NewClientBase.
Returns a pointer to an initialized Client instance or an error.
Example:
ctx := context.Background() clientParams := pinecone.NewClientBaseParams{ Headers: map[string]string{ "Authorization": "Bearer " + "<your OAuth token>" "X-Project-Id": "<Your Pinecone project ID>" }, SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClientBase(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") }
func (*Client) ConfigureIndex ¶ added in v1.0.0
func (c *Client) ConfigureIndex(ctx context.Context, name string, in ConfigureIndexParams) (*Index, error)
ConfigureIndex is used to scale a pods-based index up or down by changing the size of the pods or the number of replicas, or to enable and disable deletion protection for an index.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- name: The name of the index to configure.
- in: A pointer to a ConfigureIndexParams object that contains the parameters for configuring the index.
Note: You can only scale an index up, not down. If you want to scale an index down, you must create a new index with the desired configuration.
Returns a pointer to a configured Index object or an error.
Example:
// To scale the size of your pods-based index from "x2" to "x4": _, err := pc.ConfigureIndex(ctx, "my-pod-index", ConfigureIndexParams{PodType: "p1.x4"}) if err != nil { fmt.Printf("Failed to configure index: %v\n", err) } // To scale the number of replicas: _, err := pc.ConfigureIndex(ctx, "my-pod-index", ConfigureIndexParams{Replicas: 4}) if err != nil { fmt.Printf("Failed to configure index: %v\n", err) } // To scale both the size of your pods and the number of replicas to 4: _, err := pc.ConfigureIndex(ctx, "my-pod-index", ConfigureIndexParams{PodType: "p1.x4", Replicas: 4}) if err != nil { fmt.Printf("Failed to configure index: %v\n", err) } // To enable deletion protection: _, err := pc.ConfigureIndex(ctx, "my-index", ConfigureIndexParams{DeletionProtection: "enabled"}) if err != nil { fmt.Printf("Failed to configure index: %v\n", err) }
func (*Client) CreateCollection ¶
func (c *Client) CreateCollection(ctx context.Context, in *CreateCollectionRequest) (*Collection, error)
CreateCollection creates and initializes a new Collection via the specified Client.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: A pointer to a CreateCollectionRequest object.
Note: Collections are only available for pods-based Indexes.
Returns a pointer to a Collection object or an error.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } collection, err := pc.CreateCollection(ctx, &pinecone.CreateCollectionRequest{ Name: "my-collection", Source: "my-source-index", }) if err != nil { log.Fatalf("Failed to create collection: %v", err) } else { fmt.Printf("Successfully created collection \"%s\".", collection.Name) }
func (*Client) CreatePodIndex ¶
CreatePodIndex creates and initializes a new pods-based Index via the specified Client.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: A pointer to a CreatePodIndexRequest object. See CreatePodIndexRequest for more information.
Returns a pointer to an Index object or an error.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } podIndexMetadata := &pinecone.PodSpecMetadataConfig{ Indexed: &[]string{"title", "description"}, } indexName := "my-pod-index" idx, err := pc.CreatePodIndex(ctx, &pinecone.CreatePodIndexRequest{ Name: indexName, Dimension: 3, Metric: pinecone.Cosine, Environment: "us-west1-gcp", PodType: "s1", MetadataConfig: podIndexMetadata, }) if err != nil { log.Fatalf("Failed to create pod index:", err) } else { fmt.Printf("Successfully created pod index: %s", idx.Name) }
func (*Client) CreateServerlessIndex ¶
func (c *Client) CreateServerlessIndex(ctx context.Context, in *CreateServerlessIndexRequest) (*Index, error)
CreateServerlessIndex creates and initializes a new serverless Index via the specified Client.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: A pointer to a CreateServerlessIndexRequest object. See CreateServerlessIndexRequest for more information.
Returns a pointer to an Index object or an error.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } indexName := "my-serverless-index" idx, err := pc.CreateServerlessIndex(ctx, &pinecone.CreateServerlessIndexRequest{ Name: indexName, Dimension: 3, Metric: pinecone.Cosine, Cloud: pinecone.Aws, Region: "us-east-1", }) if err != nil { log.Fatalf("Failed to create serverless index: %s", indexName) } else { fmt.Printf("Successfully created serverless index: %s", idx.Name) }
func (*Client) DeleteCollection ¶
DeleteCollection deletes a specific Collection
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- collectionName: The name of the Collection to delete.
Note: Collections are only available for pods-based Indexes.
Returns an error if the deletion fails.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } collectionName := "my-collection" err = pc.DeleteCollection(ctx, collectionName) if err != nil { log.Fatalf("Failed to create collection: %s\n", err) } else { log.Printf("Successfully deleted collection \"%s\"\n", collectionName) }
func (*Client) DeleteIndex ¶
DeleteIndex deletes a specific Index.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- idxName: The name of the Index to delete.
Returns an error if the deletion fails.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } indexName := "the-name-of-my-index" err = pc.DeleteIndex(ctx, indexName) if err != nil { log.Fatalf("Error: %v", err) } else { fmt.Printf("Index \"%s\" deleted successfully", indexName) }
func (*Client) DescribeCollection ¶
func (c *Client) DescribeCollection(ctx context.Context, collectionName string) (*Collection, error)
DescribeCollection retrieves information about a specific Collection.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- collectionName: The name of the Collection to describe.
Returns a pointer to a Collection object or an error.
Note: Collections are only available for pods-based Indexes.
Since the returned value is a pointer to a Collection object, it will have the following fields:
- Name: The name of the Collection.
- Size: The size of the Collection in bytes.
- Status: The status of the Collection.
- Dimension: The dimensionality of the vectors stored in each record held in the Collection.
- VectorCount: The number of records stored in the Collection.
- Environment: The cloud environment where the Collection is hosted.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } collection, err := pc.DescribeCollection(ctx, "my-collection") if err != nil { log.Fatalf("Error describing collection: %v", err) } else { fmt.Printf("Collection: %+v\n", *collection) }
func (*Client) DescribeIndex ¶
DescribeIndex retrieves information about a specific Index. See Index for more information.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- idxName: The name of the Index to describe.
Returns a pointer to an Index object or an error.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } idx, err := pc.DescribeIndex(ctx, "the-name-of-my-index") if err != nil { log.Fatalf("Failed to describe index: %s", err) } else { desc := fmt.Sprintf("Description: \n Name: %s\n Dimension: %d\n Host: %s\n Metric: %s\n"+ " DeletionProtection"+ ": %s\n"+ " Spec: %+v"+ "\n Status: %+v\n", idx.Name, idx.Dimension, idx.Host, idx.Metric, idx.DeletionProtection, idx.Spec, idx.Status) fmt.Println(desc) }
func (*Client) Index ¶
func (c *Client) Index(in NewIndexConnParams, dialOpts ...grpc.DialOption) (*IndexConnection, error)
Index creates an IndexConnection to a specified host.
Parameters:
- in: A NewIndexConnParams object that includes the necessary configuration to create an IndexConnection. See NewIndexConnParams for more information.
Note: It is important to handle the error returned by this method to ensure that the IndexConnection is created successfully before making data plane calls.
Returns a pointer to an IndexConnection instance or an error.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } else { fmt.Printf("Successfully found the \"%s\" index!\n", idx.Name) } indexConnParams := pinecone.NewIndexConnParams{ Host: idx.Host, Namespace: "your-namespace", AdditionalMetadata: map[string]string{ "your-metadata-key": "your-metadata-value", }, } idxConnection, err := pc.Index(indexConnParams) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } else { log.Println("IndexConnection created successfully!") }
func (*Client) ListCollections ¶
func (c *Client) ListCollections(ctx context.Context) ([]*Collection, error)
ListCollections retrieves a list of all Collections in a Pinecone project. See Collection for more information.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
Returns a slice of pointers to Collection objects or an error.
Note: Collections are only available for pods-based Indexes.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } collections, err := pc.ListCollections(ctx) if err != nil { log.Fatalf("Failed to list collections: %v", err) } else { if len(collections) == 0 { fmt.Printf("No collections found in project") } else { fmt.Println("Collections in project:") for _, collection := range collections { fmt.Printf("- %s\n", collection.Name) } } }
func (*Client) ListIndexes ¶
ListIndexes retrieves a list of all Indexes in a Pinecone project.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
Returns a slice of pointers to Index objects or an error.
Example:
clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } idxs, err := pc.ListIndexes(ctx) if err != nil { log.Fatalf("Failed to list indexes: %v", err) } else { fmt.Println("Your project has the following indexes:") for _, idx := range idxs { fmt.Printf("- \"%s\"\n", idx.Name) } }
type Cloud ¶
type Cloud string
Cloud is the cloud provider to be used for a Pinecone serverless Index.
type Collection ¶
type Collection struct { Name string `json:"name"` Size int64 `json:"size"` Status CollectionStatus `json:"status"` Dimension int32 `json:"dimension"` VectorCount int32 `json:"vector_count"` Environment string `json:"environment"` }
Collection is a Pinecone Collection object. Only available for pod-based Indexes.
type CollectionStatus ¶
type CollectionStatus string
CollectionStatus is the status of a Pinecone Collection.
const ( CollectionStatusInitializing CollectionStatus = "Initializing" CollectionStatusReady CollectionStatus = "Ready" CollectionStatusTerminating CollectionStatus = "Terminating" )
type ConfigureIndexParams ¶ added in v1.0.0
type ConfigureIndexParams struct { PodType string Replicas int32 DeletionProtection DeletionProtection }
ConfigureIndexParams contains parameters for configuring an index. For both pod-based and serverless indexes you can configure the DeletionProtection status for an index. For pod-based indexes you can also configure the number of Replicas and the PodType. Each of the fields is optional, but at least one field must be set. See scale a pods-based index for more information.
Fields:
- PodType: (Optional) The pod size to scale the index to. For a "p1" pod type, you could pass "p1.x2" to scale your index to the "x2" size, or you could pass "p1.x4" to scale your index to the "x4" size, and so forth. Only applies to pod-based indexes.
- Replicas: (Optional) The number of replicas to scale the index to. This is capped by the maximum number of replicas allowed in your Pinecone project. To configure this number, go to app.pinecone.io, select your project, and configure the maximum number of pods.
- DeletionProtection: (Optional) DeletionProtection determines whether deletion protection is "enabled" or "disabled" for the index. When "enabled", the index cannot be deleted. Defaults to "disabled".
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } idx, err := pc.ConfigureIndex(ctx, "my-index", ConfigureIndexParams{ DeletionProtection: "enabled", Replicas: 4 })
type CreateCollectionRequest ¶
CreateCollectionRequest holds the parameters for creating a new Collection.
Fields:
- Name: (Required) The name of the Collection.
- Source: (Required) The name of the Index to be used as the source for the Collection.
To create a new Collection, use the CreateCollection method on the Client object.
Note: Collections are only available for pods-based Indexes.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } collection, err := pc.CreateCollection(ctx, &pinecone.CreateCollectionRequest{ Name: "my-collection", Source: "my-source-index", }) if err != nil { log.Fatalf("Failed to create collection: %v", err) } else { fmt.Printf("Successfully created collection \"%s\".", collection.Name) }
type CreatePodIndexRequest ¶
type CreatePodIndexRequest struct { Name string Dimension int32 Metric IndexMetric DeletionProtection DeletionProtection Environment string PodType string Shards int32 Replicas int32 SourceCollection *string MetadataConfig *PodSpecMetadataConfig }
CreatePodIndexRequest holds the parameters for creating a new pods-based Index.
Fields:
- Name: (Required) The name of the Index. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'.
- Dimension: (Required) The dimensionality of the vectors to be inserted in the Index.
- Metric: (Required) The distance metric to be used for similarity search. You can use 'euclidean', 'cosine', or 'dotproduct'.
- Environment: (Required) The cloud environment where the Index will be hosted.
- PodType: (Required) The type of pod to use for the Index. One of `s1`, `p1`, or `p2` appended with `.` and one of `x1`, `x2`, `x4`, or `x8`.
- Shards: (Optional) The number of shards to use for the Index (defaults to 1). Shards split your data across multiple pods, so you can fit more data into an Index.
- Replicas: (Optional) The number of replicas to use for the Index (defaults to 1). Replicas duplicate your Index. They provide higher availability and throughput. Replicas can be scaled up or down as your needs change.
- SourceCollection: (Optional) The name of the Collection to be used as the source for the Index.
- MetadataConfig: (Optional) The metadata configuration for the behavior of Pinecone's internal metadata Index. By default, all metadata is indexed; when `metadata_config` is present, only specified metadata fields are indexed. These configurations are only valid for use with pod-based Indexes.
- DeletionProtection: (Optional) determines whether deletion protection is "enabled" or "disabled" for the index. When "enabled", the index cannot be deleted. Defaults to "disabled".
To create a new pods-based Index, use the CreatePodIndex method on the Client object.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } podIndexMetadata := &pinecone.PodSpecMetadataConfig{ Indexed: &[]string{"title", "description"}, } indexName := "my-pod-index" idx, err := pc.CreatePodIndex(ctx, &pinecone.CreatePodIndexRequest{ Name: indexName, Dimension: 3, Metric: pinecone.Cosine, Environment: "us-west1-gcp", PodType: "s1", MetadataConfig: podIndexMetadata, }) if err != nil { log.Fatalf("Failed to create pod index: %v", err) } else { fmt.Printf("Successfully created pod index: %s", idx.Name) }
func (CreatePodIndexRequest) ReplicaCount ¶
func (req CreatePodIndexRequest) ReplicaCount() int32
ReplicaCount ensures the replica count of a pods-based Index is >1. It returns a pointer to the number of replicas on a CreatePodIndexRequest object.
func (CreatePodIndexRequest) ShardCount ¶
func (req CreatePodIndexRequest) ShardCount() int32
ShardCount ensures the number of shards on a pods-based Index is >1. It returns a pointer to the number of shards on a CreatePodIndexRequest object.
func (CreatePodIndexRequest) TotalCount ¶
func (req CreatePodIndexRequest) TotalCount() int
TotalCount calculates and returns the total number of pods (replicas*shards) on a CreatePodIndexRequest object.
type CreateServerlessIndexRequest ¶
type CreateServerlessIndexRequest struct { Name string Dimension int32 Metric IndexMetric DeletionProtection DeletionProtection Cloud Cloud Region string }
CreateServerlessIndexRequest holds the parameters for creating a new Serverless Index.
Fields:
- Name: (Required) The name of the Index. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'.
- Dimension: (Required) The dimensionality of the vectors to be inserted in the Index.
- Metric: (Required) The metric used to measure the similarity between vectors ('euclidean', 'cosine', or 'dotproduct').
- Cloud: (Required) The public cloud provider where you would like your Index hosted. For serverless Indexes, you define only the cloud and region where the Index should be hosted.
- Region: (Required) The region where you would like your Index to be created.
- DeletionProtection: (Optional) Determines whether deletion protection is "enabled" or "disabled" for the index. When "enabled", the index cannot be deleted. Defaults to "disabled".
To create a new Serverless Index, use the CreateServerlessIndex method on the Client object.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } indexName := "my-serverless-index" idx, err := pc.CreateServerlessIndex(ctx, &pinecone.CreateServerlessIndexRequest{ Name: indexName, Dimension: 3, Metric: pinecone.Cosine, Cloud: pinecone.Aws, Region: "us-east-1", }) if err != nil { log.Fatalf("Failed to create serverless index: %s", indexName) } else { fmt.Printf("Successfully created serverless index: %s", idx.Name) }
type DeletionProtection ¶ added in v1.0.0
type DeletionProtection string
DeletionProtection determines whether deletion protection is "enabled" or "disabled" for the index. When "enabled", the index cannot be deleted. Defaults to "disabled".
const ( DeletionProtectionEnabled DeletionProtection = "enabled" DeletionProtectionDisabled DeletionProtection = "disabled" )
type DescribeIndexStatsResponse ¶
type DescribeIndexStatsResponse struct { Dimension uint32 `json:"dimension"` IndexFullness float32 `json:"index_fullness"` TotalVectorCount uint32 `json:"total_vector_count"` Namespaces map[string]*NamespaceSummary `json:"namespaces,omitempty"` }
DescribeIndexStatsResponse holds the parameters for the DescribeIndexStatsResponse object, which is returned by the DescribeIndexStats method.
Fields:
- Dimension: The dimension of the index.
- IndexFullness: The fullness level of the index. Note: only available on pods-based indexes.
- TotalVectorCount: The total number of vectors in the index.
- Namespaces: The namespace(s) in the index.
type EmbedParameters ¶ added in v1.1.0
EmbedParameters contains model-specific parameters that can be used for generating embeddings.
Fields:
- InputType: (Optional) A common property used to distinguish between different types of data. For example, "passage", or "query".
- Truncate: (Optional) How to handle inputs longer than those supported by the model. if "NONE", when the input exceeds the maximum input token length, an error will be returned.
type EmbedRequest ¶ added in v1.1.0
type EmbedRequest struct { Model string TextInputs []string Parameters EmbedParameters }
EmbedRequest holds the parameters for generating embeddings for a list of input strings.
Fields:
- Model: (Required) The model to use for generating embeddings.
- TextInputs: (Required) A list of strings to generate embeddings for.
- Parameters: (Optional) EmbedParameters object that contains additional parameters to use when generating embeddings.
type FetchVectorsResponse ¶
type FetchVectorsResponse struct { Vectors map[string]*Vector `json:"vectors,omitempty"` Usage *Usage `json:"usage,omitempty"` Namespace string `json:"namespace"` }
FetchVectorsResponse holds the parameters for the FetchVectorsResponse object, which is returned by the FetchVectors method.
Fields:
- Vectors: The vectors fetched.
- Usage: The usage information for the request.
- Namespace: The namespace from which the vectors were fetched.
type Index ¶
type Index struct { Name string `json:"name"` Dimension int32 `json:"dimension"` Host string `json:"host"` Metric IndexMetric `json:"metric"` DeletionProtection DeletionProtection `json:"deletion_protection,omitempty"` Spec *IndexSpec `json:"spec,omitempty"` Status *IndexStatus `json:"status,omitempty"` }
Index is a Pinecone Index object. Can be either a pod-based or a serverless Index, depending on the IndexSpec.
func BuildPodTestIndex ¶ added in v1.0.0
func BuildServerlessTestIndex ¶ added in v1.0.0
type IndexConnection ¶
type IndexConnection struct { Namespace string // contains filtered or unexported fields }
IndexConnection holds the parameters for a Pinecone IndexConnection object.
Fields:
- Namespace: The namespace where index operations will be performed.
- additionalMetadata: Additional metadata to be sent with each RPC request.
- dataClient: The gRPC client for the index.
- grpcConn: The gRPC connection.
func (*IndexConnection) Close ¶
func (idx *IndexConnection) Close() error
Close closes the grpc.ClientConn to a Pinecone index.
Returns an error if the connection cannot be closed, otherwise returns nil.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection: %v", err) } err = idxConnection.Close() if err != nil { log.Fatalf("Failed to close index connection. Error: %v", err) }
func (*IndexConnection) DeleteAllVectorsInNamespace ¶
func (idx *IndexConnection) DeleteAllVectorsInNamespace(ctx context.Context) error
DeleteAllVectorsInNamespace deletes all vectors in a specific namespace.
Returns an error if the request fails, otherwise returns nil.
Note: You must instantiate an IndexConnection using the Index method with a Namespace in NewIndexConnParams in order to delete vectors in a namespace other than the default.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host, Namespace: "your-namespace"}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } err = idxConnection.DeleteAllVectorsInNamespace(ctx) if err != nil { log.Fatalf("Failed to delete vectors in namespace: \"%s\". Error: %s", idxConnection.Namespace, err) }
func (*IndexConnection) DeleteVectorsByFilter ¶
func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, metadataFilter *MetadataFilter) error
DeleteVectorsByFilter deletes vectors from a Pinecone index, given a filter.
Returns an error if the request fails, otherwise returns nil.
Note: DeleteVectorsByFilter is only available on pods-based indexes. Additionally, you must instantiate an IndexConnection using the Index method with a Namespace in NewIndexConnParams in order to delete vectors in a namespace other than the default.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- MetadataFilter: The filter to apply to the deletion.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } MetadataFilter := map[string]interface{}{ "genre": "classical", } filter, err := structpb.NewStruct(MetadataFilter) if err != nil { log.Fatalf("Failed to create metadata filter. Error: %v", err) } err = idxConnection.DeleteVectorsByFilter(ctx, filter) if err != nil { log.Fatalf("Failed to delete vector(s) with filter: %+v. Error: %s\n", filter, err) }
func (*IndexConnection) DeleteVectorsById ¶
func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) error
DeleteVectorsById deletes vectors by ID from a Pinecone index.
Returns an error if the request fails, otherwise returns nil. This method will also return nil if the passed vector ID does not exist in the index or namespace.
Note: You must instantiate an Index connection with a Namespace in NewIndexConnParams in order to delete vectors in a namespace other than the default: "".
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- ids: IDs of the vectors you want to delete.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host, Namespace: "custom-namespace"}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } vectorId := "your-vector-id" err = idxConnection.DeleteVectorsById(ctx, []string{vectorId}) if err != nil { log.Fatalf("Failed to delete vector with ID: %s. Error: %s\n", vectorId, err) }
func (*IndexConnection) DescribeIndexStats ¶
func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIndexStatsResponse, error)
DescribeIndexStats returns statistics about a Pinecone index.
Returns a pointer to a DescribeIndexStatsResponse object or an error if the request fails.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index:", err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } res, err := idxConnection.DescribeIndexStats(ctx) if err != nil { log.Fatalf("Failed to describe index \"%s\". Error: %s", idx.Name, err) } else { log.Fatalf("%+v", *res) }
func (*IndexConnection) DescribeIndexStatsFiltered ¶
func (idx *IndexConnection) DescribeIndexStatsFiltered(ctx context.Context, metadataFilter *MetadataFilter) (*DescribeIndexStatsResponse, error)
DescribeIndexStatsFiltered returns statistics about a Pinecone index, filtered by a given filter.
Returns a pointer to a DescribeIndexStatsResponse object or an error if the request fails.
Note: DescribeIndexStatsFiltered is only available on pods-based indexes.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- MetadataFilter: The filter to apply to the request.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } MetadataFilter := map[string]interface{}{ "genre": "classical", } filter, err := structpb.NewStruct(MetadataFilter) if err != nil { log.Fatalf("Failed to create filter %+v. Error: %s", MetadataFilter, err) } res, err := idxConnection.DescribeIndexStatsFiltered(ctx, filter) if err != nil { log.Fatalf("Failed to describe index \"%s\". Error: %s", idx.Name, err) } else { for name, summary := range res.Namespaces { fmt.Printf("Namespace: \"%s\", has %d vector(s) that match the given filter\n", name, summary.VectorCount) } }
func (*IndexConnection) FetchVectors ¶
func (idx *IndexConnection) FetchVectors(ctx context.Context, ids []string) (*FetchVectorsResponse, error)
FetchVectors fetches vectors by ID from a Pinecone index.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- ids: The unique IDs of the vectors to fetch.
Returns a pointer to any fetched vectors or an error if the request fails.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } res, err := idxConnection.FetchVectors(ctx, []string{"abc-1"}) if err != nil { log.Fatalf("Failed to fetch vectors, error: %+v", err) } if len(res.Vectors) != 0 { fmt.Println(res) } else { fmt.Println("No vectors found") }
func (*IndexConnection) ListVectors ¶
func (idx *IndexConnection) ListVectors(ctx context.Context, in *ListVectorsRequest) (*ListVectorsResponse, error)
ListVectors lists vectors in a Pinecone index. You can filter vectors by prefix, limit the number of vectors returned, and paginate through results.
Note: ListVectors is only available for Serverless indexes.
Returns a pointer to a ListVectorsResponse object or an error if the request fails.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: A ListVectorsRequest object with the parameters for the request.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } prefix := "abc" limit := uint32(10) res, err := idxConnection.ListVectors(ctx, &pinecone.ListVectorsRequest{ Prefix: &prefix, Limit: &limit, }) if err != nil { log.Fatalf("Failed to list vectors in index: %s. Error: %s\n", idx.Name, err) } if len(res.VectorIds) == 0 { fmt.Println("No vectors found") } else { fmt.Printf("Found %d vector(s)\n", len(res.VectorIds)) }
func (*IndexConnection) QueryByVectorId ¶
func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVectorIdRequest) (*QueryVectorsResponse, error)
QueryByVectorId uses a vector ID to query a Pinecone index and retrieve vectors that are most similar to the provided ID's underlying vector.
Returns a pointer to a QueryVectorsResponse object or an error if the request fails.
Note: QueryByVectorId executes a nearest neighbors search, meaning that unless TopK=1 in the QueryByVectorIdRequest object, it will return 2+ vectors. The vector with a score of 1.0 is the vector with the same ID as the query vector.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: A QueryByVectorIdRequest object with the parameters for the request.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } vectorId := "abc-1" topK := uint32(10) res, err := idxConnection.QueryByVectorId(ctx, &pinecone.QueryByVectorIdRequest{ VectorId: vectorId, TopK: topK, // number of vectors you want returned IncludeValues: true, IncludeMetadata: true, }) if err != nil { log.Fatalf("Error encountered when querying by vector ID `%s`. Error: %s", vectorId, err) } else { for _, match := range res.Matches { fmt.Printf("Match vector with ID `%s`, with score %f\n", match.Vector.Id, match.Score) } }
func (*IndexConnection) QueryByVectorValues ¶
func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryByVectorValuesRequest) (*QueryVectorsResponse, error)
QueryByVectorValues queries a Pinecone index for vectors that are most similar to a provided query vector.
Returns a pointer to a QueryVectorsResponse object or an error if the request fails.
Note: To issue a hybrid query with both dense and sparse values, your index's similarity metric must be dot-product.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: A QueryByVectorValuesRequest object with the parameters for the request.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } queryVector := []float32{1.0, 2.0} topK := uint32(10) metadataMap := map[string]interface{}{ "genre": "classical", } MetadataFilter, err := structpb.NewStruct(metadataMap) if err != nil { log.Fatalf("Failed to create metadata map. Error: %v", err) } sparseValues := pinecone.SparseValues{ Indices: []uint32{0, 1}, Values: []float32{1.0, 2.0}, } res, err := idxConnection.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{ Vector: queryVector, TopK: topK, // number of vectors to be returned MetadataFilter: MetadataFilter, SparseValues: &sparseValues, IncludeValues: true, IncludeMetadata: true, }) if err != nil { log.Fatalf("Error encountered when querying by vector: %v", err) } else { for _, match := range res.Matches { fmt.Printf("Match vector `%s`, with score %f\n", match.Vector.Id, match.Score) } }
func (*IndexConnection) UpdateVector ¶
func (idx *IndexConnection) UpdateVector(ctx context.Context, in *UpdateVectorRequest) error
UpdateVector updates a vector in a Pinecone index by ID.
Returns an error if the request fails, returns nil otherwise.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: An UpdateVectorRequest object with the parameters for the request.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } id := "abc-1" err = idxConnection.UpdateVector(ctx, &pinecone.UpdateVectorRequest{ Id: id, Values: []float32{7.0, 8.0}, }) if err != nil { log.Fatalf("Failed to update vector with ID %s. Error: %s", id, err) }
func (*IndexConnection) UpsertVectors ¶
UpsertVectors upserts vectors into a Pinecone index.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: The vectors to upsert.
Returns the number of vectors upserted or an error if the request fails.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } idx, err := pc.DescribeIndex(ctx, "your-index-name") if err != nil { log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) } idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host}) if err != nil { log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) } metadataMap := map[string]interface{}{ "genre": "classical", } metadata, err := structpb.NewStruct(metadataMap) if err != nil { log.Fatalf("Failed to create metadata map. Error: %v", err) } sparseValues := pinecone.SparseValues{ Indices: []uint32{0, 1}, Values: []float32{1.0, 2.0}, } vectors := []*pinecone.Vector{ { Id: "abc-1", Values: []float32{1.0, 2.0}, Metadata: metadata, SparseValues: &sparseValues, }, } count, err := idxConnection.UpsertVectors(ctx, vectors) if err != nil { log.Fatalf("Failed to upsert vectors. Error: %v", err) } else { log.Fatalf("Successfully upserted %d vector(s)!\n", count) }
type IndexMetric ¶
type IndexMetric string
IndexMetric is the distance metric to be used by similarity search against a Pinecone Index.
const ( Cosine IndexMetric = "cosine" // Default distance metric, ideal for textual data Dotproduct IndexMetric = "dotproduct" // Ideal for hybrid search Euclidean IndexMetric = "euclidean" // Ideal for distance-based data (e.g. lat/long points) )
type IndexSpec ¶
type IndexSpec struct { Pod *PodSpec `json:"pod,omitempty"` Serverless *ServerlessSpec `json:"serverless,omitempty"` }
IndexSpec is the infrastructure specification (pods vs serverless) of a Pinecone Index.
type IndexStatus ¶
type IndexStatus struct { Ready bool `json:"ready"` State IndexStatusState `json:"state"` }
IndexStatus is the status of a Pinecone Index.
type IndexStatusState ¶
type IndexStatusState string
IndexStatusState is the state of a Pinecone Index.
const ( InitializationFailed IndexStatusState = "InitializationFailed" Initializing IndexStatusState = "Initializing" Ready IndexStatusState = "Ready" ScalingDown IndexStatusState = "ScalingDown" ScalingDownPodSize IndexStatusState = "ScalingDownPodSize" ScalingUp IndexStatusState = "ScalingUp" ScalingUpPodSize IndexStatusState = "ScalingUpPodSize" Terminating IndexStatusState = "Terminating" )
type InferenceService ¶ added in v1.1.0
type InferenceService struct {
// contains filtered or unexported fields
}
InferenceService is a struct which exposes methods for interacting with the Pinecone Inference API. InferenceService can be accessed via the Client object through the Client.Inference namespace.
func (*InferenceService) Embed ¶ added in v1.1.0
func (i *InferenceService) Embed(ctx context.Context, in *EmbedRequest) (*control.EmbeddingsList, error)
Embed generates embeddings for a list of inputs using the specified model and (optional) parameters.
Parameters:
- ctx: A context.Context object controls the request's lifetime, allowing for the request to be canceled or to timeout according to the context's deadline.
- in: A pointer to an EmbedRequest object that contains the model t4o use for embedding generation, the list of input strings to generate embeddings for, and any additional parameters to use for generation.
Returns a pointer to an EmbeddingsList object or an error.
Example:
ctx := context.Background() clientParams := pinecone.NewClientParams{ ApiKey: "YOUR_API_KEY", SourceTag: "your_source_identifier", // optional } pc, err := pinecone.NewClient(clientParams) if err != nil { log.Fatalf("Failed to create Client: %v", err) } else { fmt.Println("Successfully created a new Client object!") } in := &pinecone.EmbedRequest{ Model: "multilingual-e5-large", TextInputs: []string{"Who created the first computer?"}, Parameters: pinecone.EmbedParameters{ InputType: "passage", Truncate: "END", }, } res, err := pc.Inference.Embed(ctx, in) if err != nil { log.Fatalf("Failed to embed: %v", err) } else { fmt.Printf("Successfull generated embeddings: %+v", res) }
type IntegrationTests ¶ added in v1.0.0
func (*IntegrationTests) SetupSuite ¶ added in v1.0.0
func (ts *IntegrationTests) SetupSuite()
func (*IntegrationTests) TearDownSuite ¶ added in v1.0.0
func (ts *IntegrationTests) TearDownSuite()
type ListVectorsRequest ¶
ListVectorsRequest holds the parameters for the ListVectorsRequest object, which is passed into the ListVectors method.
Fields:
- Prefix: (Optional) The prefix by which to filter. If unspecified, an empty string will be used which will list all vector ids in the namespace
- Limit: (Optional) The maximum number of vectors to return. If unspecified, the server will use a default value.
- PaginationToken: (Optional) The token for paginating through results.
type ListVectorsResponse ¶
type ListVectorsResponse struct { VectorIds []*string `json:"vector_ids,omitempty"` Usage *Usage `json:"usage,omitempty"` NextPaginationToken *string `json:"next_pagination_token,omitempty"` Namespace string `json:"namespace"` }
ListVectorsResponse holds the parameters for the ListVectorsResponse object, which is returned by the ListVectors method.
Fields:
- VectorIds: The unique IDs of the returned vectors.
- Usage: The usage information for the request.
- NextPaginationToken: The token for paginating through results.
- Namespace: The namespace vector ids are listed from.
type Metadata ¶
Metadata represents optional, additional information that can be attached to, or updated for, a vector in a Pinecone Index.
type MetadataFilter ¶ added in v1.0.0
MetadataFilter represents the metadata filters attached to a Pinecone request. These optional metadata filters are applied to query and deletion requests.
type NamespaceSummary ¶
type NamespaceSummary struct {
VectorCount uint32 `json:"vector_count"`
}
NamespaceSummary is a summary of stats for a Pinecone namespace.
type NewClientBaseParams ¶ added in v0.5.0
type NewClientBaseParams struct { Headers map[string]string Host string RestClient *http.Client SourceTag string }
NewClientBaseParams holds the parameters for creating a new Client instance while passing custom authentication headers. If there is no API key or authentication provided through Headers, API calls will fail.
Fields:
- Headers: (Optional) A map of HTTP headers to include in each API request. "Authorization" and "X-Project-Id" headers are required if authenticating using a JWT.
- Host: (Optional) The host URL of the Pinecone API. If not provided, the default value is "https://api.pinecone.io".
- RestClient: (Optional) An *http.Client object to use for communication with the Pinecone API.
- SourceTag: (Optional) A string used to help Pinecone attribute API activity.
See Client for code example.
type NewClientParams ¶
type NewClientParams struct { ApiKey string // required - provide through NewClientParams or environment variable PINECONE_API_KEY Headers map[string]string // optional Host string // optional RestClient *http.Client // optional SourceTag string // optional }
NewClientParams holds the parameters for creating a new Client instance while authenticating via an API key.
Fields:
- ApiKey: (Required) The API key used to authenticate with the Pinecone API. This value must be passed by the user unless it is set as an environment variable ("PINECONE_API_KEY").
- Headers: (Optional) An optional map of HTTP headers to include in each API request.
- Host: (Optional) The host URL of the Pinecone API. If not provided, the default value is "https://api.pinecone.io".
- RestClient: An optional HTTP client to use for communication with the Pinecone API.
- SourceTag: An optional string used to help Pinecone attribute API activity.
See Client for code example.
type NewIndexConnParams ¶ added in v1.0.0
type NewIndexConnParams struct { Host string // required - obtained through DescribeIndex or ListIndexes Namespace string // optional - if not provided the default namespace of "" will be used AdditionalMetadata map[string]string // optional }
NewIndexConnParams holds the parameters for creating an IndexConnection to a Pinecone index.
Fields:
- Host: (Required) The host URL of the Pinecone index. To find your host url use the DescribeIndex or ListIndexes methods. Alternatively, the host is displayed in the Pinecone web console.
- Namespace: (Optional) The index namespace to use for operations. If not provided, the default namespace of "" will be used.
- AdditionalMetadata: (Optional) Metadata to be sent with each RPC request.
See Client.Index for code example.
type PineconeError ¶ added in v0.5.0
func (*PineconeError) Error ¶ added in v0.5.0
func (pe *PineconeError) Error() string
type PodSpec ¶
type PodSpec struct { Environment string `json:"environment"` PodType string `json:"pod_type"` PodCount int32 `json:"pod_count"` Replicas int32 `json:"replicas"` ShardCount int32 `json:"shard_count"` SourceCollection *string `json:"source_collection,omitempty"` MetadataConfig *PodSpecMetadataConfig `json:"metadata_config,omitempty"` }
PodSpec is the infrastructure specification of a pod-based Pinecone Index. Only available for pod-based Indexes.
type PodSpecMetadataConfig ¶
type PodSpecMetadataConfig struct {
Indexed *[]string `json:"indexed,omitempty"`
}
PodSpecMetadataConfig represents the metadata fields to be indexed when a Pinecone Index is created.
type QueryByVectorIdRequest ¶
type QueryByVectorIdRequest struct { VectorId string TopK uint32 IncludeValues bool IncludeMetadata bool SparseValues *SparseValues // contains filtered or unexported fields }
QueryByVectorIdRequest holds the parameters for the QueryByVectorIdRequest object, which is passed into the QueryByVectorId method.
Fields:
- VectorId: (Required) The unique ID of the vector used to find similar vectors.
- TopK: (Required) The number of vectors to return.
- MetadataFilter: (Optional) The filter to apply to your query.
- IncludeValues: (Optional) Whether to include the values of the vectors in the response.
- IncludeMetadata: (Optional) Whether to include the metadata associated with the vectors in the response.
- SparseValues: (Optional) The sparse values of the query vector, if applicable.
type QueryByVectorValuesRequest ¶
type QueryByVectorValuesRequest struct { Vector []float32 TopK uint32 MetadataFilter *MetadataFilter IncludeValues bool IncludeMetadata bool SparseValues *SparseValues }
QueryByVectorValuesRequest holds the parameters for the QueryByVectorValuesRequest object, which is passed into the QueryByVectorValues method.
Fields:
- Vector: (Required) The query vector used to find similar vectors.
- TopK: (Required) The number of vectors to return.
- MetadataFilter: (Optional) The filter to apply to your query.
- IncludeValues: (Optional) Whether to include the values of the vectors in the response.
- IncludeMetadata: (Optional) Whether to include the metadata associated with the vectors in the response.
- SparseValues: (Optional) The sparse values of the query vector, if applicable.
type QueryVectorsResponse ¶
type QueryVectorsResponse struct { Matches []*ScoredVector `json:"matches,omitempty"` Usage *Usage `json:"usage,omitempty"` Namespace string `json:"namespace"` }
QueryVectorsResponse holds the parameters for the QueryVectorsResponse object, which is returned by the QueryByVectorValues method.
Fields:
- Matches: The vectors that are most similar to the query vector.
- Usage: The usage information for the request.
- Namespace: The namespace from which the vectors were queried.
type ScoredVector ¶
ScoredVector is a vector with an associated similarity score calculated according to the distance metric of the Index.
type ServerlessSpec ¶
ServerlessSpec is the infrastructure specification of a serverless Pinecone Index. Only available for serverless Indexes.
type SparseValues ¶
type SparseValues struct { Indices []uint32 `json:"indices,omitempty"` Values []float32 `json:"values,omitempty"` }
SparseValues is a sparse vector objects, most commonly used for hybrid search.
type UpdateVectorRequest ¶
type UpdateVectorRequest struct { Id string Values []float32 SparseValues *SparseValues Metadata *Metadata }
UpdateVectorRequest holds the parameters for the UpdateVectorRequest object, which is passed into the UpdateVector method.
Fields:
- Id: (Required) The unique ID of the vector to update.
- Values: The values with which you want to update the vector.
- SparseValues: The sparse values with which you want to update the vector.
- Metadata: The metadata with which you want to update the vector.
type Usage ¶
type Usage struct {
ReadUnits uint32 `json:"read_units"`
}
Usage is the usage stats (Read Units) for a Pinecone Index.
type Vector ¶
type Vector struct { Id string `json:"id"` Values []float32 `json:"values,omitempty"` SparseValues *SparseValues `json:"sparse_values,omitempty"` Metadata *Metadata `json:"metadata,omitempty"` }
Vector is a dense or sparse vector object with optional metadata.