## 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 } ```