# Vectorize # Indexes ## List Vectorize Indexes `client.Vectorize.Indexes.List(ctx, query) (*SinglePage[CreateIndex], error)` **get** `/accounts/{account_id}/vectorize/v2/indexes` Returns a list of Vectorize Indexes ### Parameters - `query IndexListParams` - `AccountID param.Field[string]` Identifier ### Returns - `type CreateIndex struct{…}` - `Config IndexDimensionConfiguration` - `Dimensions int64` Specifies the number of dimensions for the index - `Metric IndexDimensionConfigurationMetric` Specifies the type of metric to use calculating distance. - `const IndexDimensionConfigurationMetricCosine IndexDimensionConfigurationMetric = "cosine"` - `const IndexDimensionConfigurationMetricEuclidean IndexDimensionConfigurationMetric = "euclidean"` - `const IndexDimensionConfigurationMetricDOTProduct IndexDimensionConfigurationMetric = "dot-product"` - `CreatedOn Time` Specifies the timestamp the resource was created as an ISO8601 string. - `Description string` Specifies the description of the index. - `ModifiedOn Time` Specifies the timestamp the resource was modified as an ISO8601 string. - `Name string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.Vectorize.Indexes.List(context.TODO(), vectorize.IndexListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": [ { "config": { "dimensions": 768, "metric": "cosine" }, "created_on": "2022-11-15T18:25:44.442097Z", "description": "This is my example index.", "modified_on": "2022-11-15T18:25:44.442097Z", "name": "example-index" } ], "success": true } ``` ## Get Vectorize Index `client.Vectorize.Indexes.Get(ctx, indexName, query) (*CreateIndex, error)` **get** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}` Returns the specified Vectorize Index. ### Parameters - `indexName string` - `query IndexGetParams` - `AccountID param.Field[string]` Identifier ### Returns - `type CreateIndex struct{…}` - `Config IndexDimensionConfiguration` - `Dimensions int64` Specifies the number of dimensions for the index - `Metric IndexDimensionConfigurationMetric` Specifies the type of metric to use calculating distance. - `const IndexDimensionConfigurationMetricCosine IndexDimensionConfigurationMetric = "cosine"` - `const IndexDimensionConfigurationMetricEuclidean IndexDimensionConfigurationMetric = "euclidean"` - `const IndexDimensionConfigurationMetricDOTProduct IndexDimensionConfigurationMetric = "dot-product"` - `CreatedOn Time` Specifies the timestamp the resource was created as an ISO8601 string. - `Description string` Specifies the description of the index. - `ModifiedOn Time` Specifies the timestamp the resource was modified as an ISO8601 string. - `Name string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) createIndex, err := client.Vectorize.Indexes.Get( context.TODO(), "example-index", vectorize.IndexGetParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", createIndex.Config) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "config": { "dimensions": 768, "metric": "cosine" }, "created_on": "2022-11-15T18:25:44.442097Z", "description": "This is my example index.", "modified_on": "2022-11-15T18:25:44.442097Z", "name": "example-index" }, "success": true } ``` ## Create Vectorize Index `client.Vectorize.Indexes.New(ctx, params) (*CreateIndex, error)` **post** `/accounts/{account_id}/vectorize/v2/indexes` Creates and returns a new Vectorize Index. ### Parameters - `params IndexNewParams` - `AccountID param.Field[string]` Path param: Identifier - `Config param.Field[IndexNewParamsConfig]` Body param: Specifies the type of configuration to use for the index. - `type IndexDimensionConfiguration struct{…}` - `Dimensions int64` Specifies the number of dimensions for the index - `Metric IndexDimensionConfigurationMetric` Specifies the type of metric to use calculating distance. - `const IndexDimensionConfigurationMetricCosine IndexDimensionConfigurationMetric = "cosine"` - `const IndexDimensionConfigurationMetricEuclidean IndexDimensionConfigurationMetric = "euclidean"` - `const IndexDimensionConfigurationMetricDOTProduct IndexDimensionConfigurationMetric = "dot-product"` - `type IndexNewParamsConfigVectorizeIndexPresetConfiguration struct{…}` - `Preset IndexNewParamsConfigVectorizeIndexPresetConfigurationPreset` Specifies the preset to use for the index. - `const IndexNewParamsConfigVectorizeIndexPresetConfigurationPresetCfBaaiBgeSmallEnV1_5 IndexNewParamsConfigVectorizeIndexPresetConfigurationPreset = "@cf/baai/bge-small-en-v1.5"` - `const IndexNewParamsConfigVectorizeIndexPresetConfigurationPresetCfBaaiBgeBaseEnV1_5 IndexNewParamsConfigVectorizeIndexPresetConfigurationPreset = "@cf/baai/bge-base-en-v1.5"` - `const IndexNewParamsConfigVectorizeIndexPresetConfigurationPresetCfBaaiBgeLargeEnV1_5 IndexNewParamsConfigVectorizeIndexPresetConfigurationPreset = "@cf/baai/bge-large-en-v1.5"` - `const IndexNewParamsConfigVectorizeIndexPresetConfigurationPresetOpenAITextEmbeddingAda002 IndexNewParamsConfigVectorizeIndexPresetConfigurationPreset = "openai/text-embedding-ada-002"` - `const IndexNewParamsConfigVectorizeIndexPresetConfigurationPresetCohereEmbedMultilingualV2_0 IndexNewParamsConfigVectorizeIndexPresetConfigurationPreset = "cohere/embed-multilingual-v2.0"` - `Name param.Field[string]` Body param - `Description param.Field[string]` Body param: Specifies the description of the index. ### Returns - `type CreateIndex struct{…}` - `Config IndexDimensionConfiguration` - `Dimensions int64` Specifies the number of dimensions for the index - `Metric IndexDimensionConfigurationMetric` Specifies the type of metric to use calculating distance. - `const IndexDimensionConfigurationMetricCosine IndexDimensionConfigurationMetric = "cosine"` - `const IndexDimensionConfigurationMetricEuclidean IndexDimensionConfigurationMetric = "euclidean"` - `const IndexDimensionConfigurationMetricDOTProduct IndexDimensionConfigurationMetric = "dot-product"` - `CreatedOn Time` Specifies the timestamp the resource was created as an ISO8601 string. - `Description string` Specifies the description of the index. - `ModifiedOn Time` Specifies the timestamp the resource was modified as an ISO8601 string. - `Name string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) createIndex, err := client.Vectorize.Indexes.New(context.TODO(), vectorize.IndexNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Config: cloudflare.F[vectorize.IndexNewParamsConfigUnion](vectorize.IndexDimensionConfigurationParam{ Dimensions: cloudflare.F(int64(768)), Metric: cloudflare.F(vectorize.IndexDimensionConfigurationMetricCosine), }), Name: cloudflare.F("example-index"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", createIndex.Config) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "config": { "dimensions": 768, "metric": "cosine" }, "created_on": "2022-11-15T18:25:44.442097Z", "description": "This is my example index.", "modified_on": "2022-11-15T18:25:44.442097Z", "name": "example-index" }, "success": true } ``` ## Delete Vectorize Index `client.Vectorize.Indexes.Delete(ctx, indexName, body) (*unknown, error)` **delete** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}` Deletes the specified Vectorize Index. ### Parameters - `indexName string` - `body IndexDeleteParams` - `AccountID param.Field[string]` Identifier ### Returns - `type IndexDeleteResponseEnvelopeResult interface{…}` - `unknown` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) index, err := client.Vectorize.Indexes.Delete( context.TODO(), "example-index", vectorize.IndexDeleteParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", index) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": {}, "success": true } ``` ## Insert Vectors `client.Vectorize.Indexes.Insert(ctx, indexName, params) (*IndexInsertResponse, error)` **post** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/insert` Inserts vectors into the specified index and returns a mutation id corresponding to the vectors enqueued for insertion. ### Parameters - `indexName string` - `params IndexInsertParams` - `AccountID param.Field[string]` Path param: Identifier - `Body param.Field[Reader]` Body param: ndjson file containing vectors to insert. - `UnparsableBehavior param.Field[IndexInsertParamsUnparsableBehavior]` Query param: Behavior for ndjson parse failures. - `const IndexInsertParamsUnparsableBehaviorError IndexInsertParamsUnparsableBehavior = "error"` - `const IndexInsertParamsUnparsableBehaviorDiscard IndexInsertParamsUnparsableBehavior = "discard"` ### Returns - `type IndexInsertResponse struct{…}` - `MutationID string` The unique identifier for the async mutation operation containing the changeset. ### Example ```go package main import ( "bytes" "context" "fmt" "io" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.Vectorize.Indexes.Insert( context.TODO(), "example-index", vectorize.IndexInsertParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Body: io.Reader(bytes.NewBuffer([]byte("Example data"))), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.MutationID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "mutationId": "0000aaaa-11bb-22cc-33dd-444444eeeeee" }, "success": true } ``` ## Query Vectors `client.Vectorize.Indexes.Query(ctx, indexName, params) (*IndexQueryResponse, error)` **post** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/query` Finds vectors closest to a given vector in an index. ### Parameters - `indexName string` - `params IndexQueryParams` - `AccountID param.Field[string]` Path param: Identifier - `Vector param.Field[[]float64]` Body param: The search vector that will be used to find the nearest neighbors. - `Filter param.Field[unknown]` Body param: A metadata filter expression used to limit nearest neighbor results. - `ReturnMetadata param.Field[IndexQueryParamsReturnMetadata]` Body param: Whether to return no metadata, indexed metadata or all metadata associated with the closest vectors. - `const IndexQueryParamsReturnMetadataNone IndexQueryParamsReturnMetadata = "none"` - `const IndexQueryParamsReturnMetadataIndexed IndexQueryParamsReturnMetadata = "indexed"` - `const IndexQueryParamsReturnMetadataAll IndexQueryParamsReturnMetadata = "all"` - `ReturnValues param.Field[bool]` Body param: Whether to return the values associated with the closest vectors. - `TopK param.Field[float64]` Body param: The number of nearest neighbors to find. ### Returns - `type IndexQueryResponse struct{…}` - `Count int64` Specifies the count of vectors returned by the search - `Matches []IndexQueryResponseMatch` Array of vectors matched by the search - `ID string` Identifier for a Vector - `Metadata unknown` - `Namespace string` - `Score float64` The score of the vector according to the index's distance metric - `Values []float64` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.Vectorize.Indexes.Query( context.TODO(), "example-index", vectorize.IndexQueryParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Vector: cloudflare.F([]float64{0.500000, 0.500000, 0.500000}), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.Count) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "count": 0, "matches": [ { "id": "some-vector-id-023e105f4ecef8ad9ca31a8372d0c353", "metadata": {}, "namespace": "namespace", "score": 0, "values": [ 0 ] } ] }, "success": true } ``` ## Upsert Vectors `client.Vectorize.Indexes.Upsert(ctx, indexName, params) (*IndexUpsertResponse, error)` **post** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/upsert` Upserts vectors into the specified index, creating them if they do not exist and returns a mutation id corresponding to the vectors enqueued for upsertion. ### Parameters - `indexName string` - `params IndexUpsertParams` - `AccountID param.Field[string]` Path param: Identifier - `Body param.Field[Reader]` Body param: ndjson file containing vectors to upsert. - `UnparsableBehavior param.Field[IndexUpsertParamsUnparsableBehavior]` Query param: Behavior for ndjson parse failures. - `const IndexUpsertParamsUnparsableBehaviorError IndexUpsertParamsUnparsableBehavior = "error"` - `const IndexUpsertParamsUnparsableBehaviorDiscard IndexUpsertParamsUnparsableBehavior = "discard"` ### Returns - `type IndexUpsertResponse struct{…}` - `MutationID string` The unique identifier for the async mutation operation containing the changeset. ### Example ```go package main import ( "bytes" "context" "fmt" "io" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.Vectorize.Indexes.Upsert( context.TODO(), "example-index", vectorize.IndexUpsertParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Body: io.Reader(bytes.NewBuffer([]byte("Example data"))), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.MutationID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "mutationId": "0000aaaa-11bb-22cc-33dd-444444eeeeee" }, "success": true } ``` ## Delete Vectors By Identifier `client.Vectorize.Indexes.DeleteByIDs(ctx, indexName, params) (*IndexDeleteByIDsResponse, error)` **post** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/delete_by_ids` Delete a set of vectors from an index by their vector identifiers. ### Parameters - `indexName string` - `params IndexDeleteByIDsParams` - `AccountID param.Field[string]` Path param: Identifier - `IDs param.Field[[]string]` Body param: A list of vector identifiers to delete from the index indicated by the path. ### Returns - `type IndexDeleteByIDsResponse struct{…}` - `MutationID string` The unique identifier for the async mutation operation containing the changeset. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.Vectorize.Indexes.DeleteByIDs( context.TODO(), "example-index", vectorize.IndexDeleteByIDsParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.MutationID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "mutationId": "0000aaaa-11bb-22cc-33dd-444444eeeeee" }, "success": true } ``` ## Get Vectors By Identifier `client.Vectorize.Indexes.GetByIDs(ctx, indexName, params) (*IndexGetByIDsResponse, error)` **post** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/get_by_ids` Get a set of vectors from an index by their vector identifiers. ### Parameters - `indexName string` - `params IndexGetByIDsParams` - `AccountID param.Field[string]` Path param: Identifier - `IDs param.Field[[]string]` Body param: A list of vector identifiers to retrieve from the index indicated by the path. ### Returns - `type IndexGetByIDsResponse interface{…}` Array of vectors with matching ids. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.Vectorize.Indexes.GetByIDs( context.TODO(), "example-index", vectorize.IndexGetByIDsParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": [ { "id": "some-vector-id", "metadata": { "another-key": "another-value", "customer-id": 442 }, "values": [ 0.812, 0.621, 0.261 ] }, { "id": "other-vector-id", "metadata": { "another-key": "with-a-value", "customer-id": 2151 }, "namespace": "namespaced", "values": [ 0.961, 0.751, 0.661 ] } ], "success": true } ``` ## Get Vectorize Index Info `client.Vectorize.Indexes.Info(ctx, indexName, query) (*IndexInfoResponse, error)` **get** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/info` Get information about a vectorize index. ### Parameters - `indexName string` - `query IndexInfoParams` - `AccountID param.Field[string]` Identifier ### Returns - `type IndexInfoResponse struct{…}` - `Dimensions int64` Specifies the number of dimensions for the index - `ProcessedUpToDatetime Time` Specifies the timestamp the last mutation batch was processed as an ISO8601 string. - `ProcessedUpToMutation string` The unique identifier for the async mutation operation containing the changeset. - `VectorCount int64` Specifies the number of vectors present in the index ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.Vectorize.Indexes.Info( context.TODO(), "example-index", vectorize.IndexInfoParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.Dimensions) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "dimensions": 768, "processedUpToDatetime": "2024-07-22T18:25:44.442097Z", "processedUpToMutation": "0000aaaa-11bb-22cc-33dd-444444eeeeee", "vectorCount": 300000 }, "success": true } ``` ## List Vectors `client.Vectorize.Indexes.ListVectors(ctx, indexName, params) (*IndexListVectorsResponse, error)` **get** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/list` Returns a paginated list of vector identifiers from the specified index. ### Parameters - `indexName string` - `params IndexListVectorsParams` - `AccountID param.Field[string]` Path param: Identifier - `Count param.Field[int64]` Query param: Maximum number of vectors to return - `Cursor param.Field[string]` Query param: Cursor for pagination to get the next page of results ### Returns - `type IndexListVectorsResponse struct{…}` - `Count int64` Number of vectors returned in this response - `IsTruncated bool` Whether there are more vectors available beyond this response - `TotalCount int64` Total number of vectors in the index - `Vectors []IndexListVectorsResponseVector` Array of vector items - `ID string` Identifier for a Vector - `CursorExpirationTimestamp Time` When the cursor expires as an ISO8601 string - `NextCursor string` Cursor for the next page of results ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.Vectorize.Indexes.ListVectors( context.TODO(), "example-index", vectorize.IndexListVectorsParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.Count) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "count": 100, "isTruncated": true, "totalCount": 500, "vectors": [ { "id": "some-vector-id-023e105f4ecef8ad9ca31a8372d0c353" } ], "cursorExpirationTimestamp": "2025-08-12T20:32:52.469144957+00:00", "nextCursor": "suUTaDY5PFUiRweVccnzyt9n75suNPbXHPshvCzue5mHjtj7Letjvzlza9eGj099" }, "success": true } ``` ## Domain Types ### Create Index - `type CreateIndex struct{…}` - `Config IndexDimensionConfiguration` - `Dimensions int64` Specifies the number of dimensions for the index - `Metric IndexDimensionConfigurationMetric` Specifies the type of metric to use calculating distance. - `const IndexDimensionConfigurationMetricCosine IndexDimensionConfigurationMetric = "cosine"` - `const IndexDimensionConfigurationMetricEuclidean IndexDimensionConfigurationMetric = "euclidean"` - `const IndexDimensionConfigurationMetricDOTProduct IndexDimensionConfigurationMetric = "dot-product"` - `CreatedOn Time` Specifies the timestamp the resource was created as an ISO8601 string. - `Description string` Specifies the description of the index. - `ModifiedOn Time` Specifies the timestamp the resource was modified as an ISO8601 string. - `Name string` ### Index Delete Vectors By ID - `type IndexDeleteVectorsByID struct{…}` - `Count int64` The count of the vectors successfully deleted. - `IDs []string` Array of vector identifiers of the vectors that were successfully processed for deletion. ### Index Dimension Configuration - `type IndexDimensionConfiguration struct{…}` - `Dimensions int64` Specifies the number of dimensions for the index - `Metric IndexDimensionConfigurationMetric` Specifies the type of metric to use calculating distance. - `const IndexDimensionConfigurationMetricCosine IndexDimensionConfigurationMetric = "cosine"` - `const IndexDimensionConfigurationMetricEuclidean IndexDimensionConfigurationMetric = "euclidean"` - `const IndexDimensionConfigurationMetricDOTProduct IndexDimensionConfigurationMetric = "dot-product"` ### Index Insert - `type IndexInsert struct{…}` - `Count int64` Specifies the count of the vectors successfully inserted. - `IDs []string` Array of vector identifiers of the vectors successfully inserted. ### Index Query - `type IndexQuery struct{…}` - `Count int64` Specifies the count of vectors returned by the search - `Matches []IndexQueryMatch` Array of vectors matched by the search - `ID string` Identifier for a Vector - `Metadata unknown` - `Score float64` The score of the vector according to the index's distance metric - `Values []float64` ### Index Upsert - `type IndexUpsert struct{…}` - `Count int64` Specifies the count of the vectors successfully inserted. - `IDs []string` Array of vector identifiers of the vectors successfully inserted. # Metadata Index ## List Metadata Indexes `client.Vectorize.Indexes.MetadataIndex.List(ctx, indexName, query) (*IndexMetadataIndexListResponse, error)` **get** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/metadata_index/list` List Metadata Indexes for the specified Vectorize Index. ### Parameters - `indexName string` - `query IndexMetadataIndexListParams` - `AccountID param.Field[string]` Identifier ### Returns - `type IndexMetadataIndexListResponse struct{…}` - `MetadataIndexes []IndexMetadataIndexListResponseMetadataIndex` Array of indexed metadata properties. - `IndexType IndexMetadataIndexListResponseMetadataIndexesIndexType` Specifies the type of indexed metadata property. - `const IndexMetadataIndexListResponseMetadataIndexesIndexTypeString IndexMetadataIndexListResponseMetadataIndexesIndexType = "string"` - `const IndexMetadataIndexListResponseMetadataIndexesIndexTypeNumber IndexMetadataIndexListResponseMetadataIndexesIndexType = "number"` - `const IndexMetadataIndexListResponseMetadataIndexesIndexTypeBoolean IndexMetadataIndexListResponseMetadataIndexesIndexType = "boolean"` - `PropertyName string` Specifies the indexed metadata property. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) metadataIndices, err := client.Vectorize.Indexes.MetadataIndex.List( context.TODO(), "example-index", vectorize.IndexMetadataIndexListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", metadataIndices.MetadataIndexes) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "metadataIndexes": [ { "indexType": "number", "propertyName": "some-num-prop" }, { "indexType": "string", "propertyName": "some-str-prop" }, { "indexType": "boolean", "propertyName": "some-bool-prop" } ] }, "success": true } ``` ## Create Metadata Index `client.Vectorize.Indexes.MetadataIndex.New(ctx, indexName, params) (*IndexMetadataIndexNewResponse, error)` **post** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/metadata_index/create` Enable metadata filtering based on metadata property. Limited to 10 properties. ### Parameters - `indexName string` - `params IndexMetadataIndexNewParams` - `AccountID param.Field[string]` Path param: Identifier - `IndexType param.Field[IndexMetadataIndexNewParamsIndexType]` Body param: Specifies the type of metadata property to index. - `const IndexMetadataIndexNewParamsIndexTypeString IndexMetadataIndexNewParamsIndexType = "string"` - `const IndexMetadataIndexNewParamsIndexTypeNumber IndexMetadataIndexNewParamsIndexType = "number"` - `const IndexMetadataIndexNewParamsIndexTypeBoolean IndexMetadataIndexNewParamsIndexType = "boolean"` - `PropertyName param.Field[string]` Body param: Specifies the metadata property to index. ### Returns - `type IndexMetadataIndexNewResponse struct{…}` - `MutationID string` The unique identifier for the async mutation operation containing the changeset. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) metadataIndex, err := client.Vectorize.Indexes.MetadataIndex.New( context.TODO(), "example-index", vectorize.IndexMetadataIndexNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), IndexType: cloudflare.F(vectorize.IndexMetadataIndexNewParamsIndexTypeString), PropertyName: cloudflare.F("random_metadata_property"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", metadataIndex.MutationID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "mutationId": "0000aaaa-11bb-22cc-33dd-444444eeeeee" }, "success": true } ``` ## Delete Metadata Index `client.Vectorize.Indexes.MetadataIndex.Delete(ctx, indexName, params) (*IndexMetadataIndexDeleteResponse, error)` **post** `/accounts/{account_id}/vectorize/v2/indexes/{index_name}/metadata_index/delete` Allow Vectorize to delete the specified metadata index. ### Parameters - `indexName string` - `params IndexMetadataIndexDeleteParams` - `AccountID param.Field[string]` Path param: Identifier - `PropertyName param.Field[string]` Body param: Specifies the metadata property for which the index must be deleted. ### Returns - `type IndexMetadataIndexDeleteResponse struct{…}` - `MutationID string` The unique identifier for the async mutation operation containing the changeset. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/vectorize" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) metadataIndex, err := client.Vectorize.Indexes.MetadataIndex.Delete( context.TODO(), "example-index", vectorize.IndexMetadataIndexDeleteParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), PropertyName: cloudflare.F("random_metadata_property"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", metadataIndex.MutationID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "mutationId": "0000aaaa-11bb-22cc-33dd-444444eeeeee" }, "success": true } ```