Skip to content

vdaas/vald-client-go

Folders and files

NameName
Last commit message
Last commit date
Nov 14, 2024
Jan 7, 2025
Jul 25, 2024
Jan 7, 2025
Jan 13, 2021
Aug 2, 2024
Feb 14, 2025
Jan 7, 2025
Nov 14, 2024
May 30, 2023
Feb 14, 2025
Dec 25, 2024
Feb 14, 2025
Feb 14, 2025
Feb 13, 2025

Repository files navigation

vald-client-go

License: Apache 2.0 release Go Reference Go Version Codacy Badge Go Report Card DepShield Badge FOSSA Status DeepSource CLA Slack Twitter

example code

	// Create a Vald clien connection for Vald cluster.
	conn, err := grpc.DialContext(ctx, "addr to cluster", grpc.WithInsecure())
	if err != nil {
		log.Fatal(err)
	}

	// Creates Vald client for gRPC.
	client := vald.NewValdClient(conn)

	// Insert sample vector.
	_, err := client.Insert(ctx, &payload.Insert_Request{
		Vector: &payload.Object_Vector{
			Id:     "id of vector",
			Vector: []float32{0.1, 0.2, 0.3}, // some feature dense vector here.
		}})
	if err != nil {
		log.Fatal(err)
	}

	// WARN you may need to wait a minutes until index creation.

	// Search sample vector.
	res, err := client.Search(ctx, &payload.Search_Request{
		Vector: vec,
		// Conditions for hitting the search.
		Config: &payload.Search_Config{
			Num:     10,        // the number of search results
			Radius:  -1,        // Radius is used to determine the space of search candidate radius for neighborhood vectors. -1 means infinite circle.
			Epsilon: 0.1,       // Epsilon is used to determines how much to expand from search candidate radius.
			Timeout: 100000000, // Timeout is used for search time deadline. The unit is nano-seconds.
		}})
	if err != nil {
		log.Fatal(err)
	}

	// Remove vector.
	_, err := client.Remove(ctx, &payload.Remove_Request{
		Id: &payload.Object_ID{
			Id: "id of vector",
		}})
	if err != nil {
		log.Fatal(err)
	}

FOSSA Status