Help us shape the future of Go! Take the 2026 Go Developer Survey

vectorsearch

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefineRetriever

func DefineRetriever(ctx context.Context, g *genkit.Genkit, cfg Config, opts *ai.RetrieverOptions) (ai.Retriever, error)

DefineRetriever defines a Retriever with the given configuration.

func GetBigQueryDocumentIndexer

func GetBigQueryDocumentIndexer(bqClient *bigquery.Client, datasetID, tableID string) func(ctx context.Context, docs []*ai.Document) ([]string, error)

GetBigQueryDocumentIndexer creates a BigQuery Document Indexer. This function returns a DocumentIndexer function that indexes documents into a BigQuery table. It generates a random ID for each document and stores the content and metadata as JSON strings.

func Index

func Index(ctx context.Context, g *genkit.Genkit, params IndexParams, documentIndexer DocumentIndexer) error

Index indexes documents into a Vertex AI index.

Types

type BigQueryDocumentRow

type BigQueryDocumentRow struct {
	ID       string `bigquery:"id"`
	Content  string `bigquery:"content"`  // Stored as JSON string
	Metadata string `bigquery:"metadata"` // Stored as JSON string
}

BigQueryDocumentRow defines the structure of a row in the BigQuery table.

type Config

type Config struct {
	IndexID string // The unique ID of the vector search index to use.
}

Config represents the configuration settings for the Vertex AI vector search plugin.

type CrowdingAttribute

type CrowdingAttribute struct {
	CrowdingAttribute string `json:"crowdingAttribute,omitempty"` // The value of the crowding tag.
}

CrowdingAttribute represents an optional attribute used for controlling result diversity (crowding).

type Datapoint

type Datapoint struct {
	DatapointId      string            `json:"datapointId"`                // The unique ID of the data point.
	FeatureVector    []float32         `json:"featureVector"`              // The numerical vector embedding of the data point.
	Restricts        []Restrict        `json:"restricts,omitempty"`        // Categorical restrictions associated with this data point.
	NumericRestricts []NumericRestrict `json:"numericRestricts,omitempty"` // Numerical restrictions associated with this data point.
	CrowdingTag      CrowdingAttribute `json:"crowdingTag,omitempty"`      // Optional crowding attribute for diversity control.
}

Datapoint represents the structure of a single data point returned in the FindNeighbors response.

type DocumentIndexer

type DocumentIndexer func(ctx context.Context, docs []*ai.Document) ([]string, error)

DocumentIndexer defines the interface (function type) for indexing documents into a vector search index.

func GetFirestoreDocumentIndexer

func GetFirestoreDocumentIndexer(db *firestore.Client, collectionName string) DocumentIndexer

GetFirestoreDocumentIndexer creates a Firestore Document Indexer. This function returns a DocumentIndexer function that indexes documents into a Firestore collection.

type DocumentRetriever

type DocumentRetriever func(ctx context.Context, neighbors []Neighbor, options any) ([]*ai.Document, error)

DocumentRetriever defines the interface (function type) for retrieving original documents given a set of search results (neighbors).

func GetBigQueryDocumentRetriever

func GetBigQueryDocumentRetriever(bqClient *bigquery.Client, datasetID, tableID string) DocumentRetriever

GetBigQueryDocumentRetriever creates a BigQuery Document Retriever. This function returns a DocumentRetriever function that retrieves documents from a BigQuery table based on the provided neighbors' IDs.

func GetFirestoreDocumentRetriever

func GetFirestoreDocumentRetriever(db *firestore.Client, collectionName string) DocumentRetriever

GetFirestoreDocumentRetriever creates a Firestore Document Retriever. This function returns a DocumentRetriever function that retrieves documents from a Firestore collection based on the provided Vertex AI Vector Search neighbors' IDs.

type FindNeighborsParams

type FindNeighborsParams struct {
	FeatureVector    []float32           // The vector embedding of the query content.
	NeighborCount    int                 // The desired number of nearest neighbors to retrieve.
	AuthClient       *google.Credentials // Authentication credentials for the API call.
	ProjectNumber    string              // The numeric ID of the Google Cloud project.
	Location         string              // The geographical region of the index endpoint.
	IndexEndpointID  string              // The ID of the specific index endpoint to query.
	PublicDomainName string              // The public domain name of the Vertex AI service.
	DeployedIndexID  string              // The ID of the deployed index within the endpoint.
	Restricts        []Restrict          // Categorical restrictions to apply to the search query.
	NumericRestricts []NumericRestrict   // Numerical restrictions to apply to the search query.
}

FindNeighborsParams represents the parameters required to query a public endpoint for finding nearest neighbors in a vector search index.

type FindNeighborsResponse

type FindNeighborsResponse struct {
	NearestNeighbors []struct {
		Neighbors []Neighbor `json:"neighbors"` // A list of the nearest neighbors found for each query.
	} `json:"nearestNeighbors"`
}

FindNeighborsResponse represents the structured response from the Vertex AI FindNeighbors API.

type IndexDatapoint

type IndexDatapoint struct {
	DatapointID      string            `json:"datapoint_id"`                // A unique identifier for this data point.
	FeatureVector    []float32         `json:"feature_vector"`              // The numerical vector embedding of the data point.
	Restricts        []Restrict        `json:"restricts,omitempty"`         // Optional categorical restrictions for the data point.
	NumericRestricts []NumericRestrict `json:"numeric_restricts,omitempty"` // Optional numerical restrictions for the data point.
	CrowdingTag      string            `json:"crowding_tag,omitempty"`      // An optional tag for crowding control in search results.
}

IndexDatapoint represents a single data point to be indexed in the vector search.

type IndexParams

type IndexParams struct {
	Docs            []*ai.Document // The documents to be indexed.
	Embedder        ai.Embedder    // The AI embedder used to convert documents into vector embeddings.
	EmbedderOptions any            // Optional settings specific to the chosen embedder.
	ProjectID       string         // The Google Cloud Project ID where the index is located.
	Location        string         // The geographical region of the index (e.g., "us-central1").
	IndexID         string         // The unique ID of the vector search index.
}

IndexParams represents the parameters required for indexing documents into a vector search index.

type Neighbor

type Neighbor struct {
	Datapoint Datapoint `json:"datapoint"` // The actual data point found.
	Distance  float64   `json:"distance"`  // The calculated distance (similarity score) to the query.
}

Neighbor represents a single nearest neighbor result, including the datapoint and its distance.

type NumericRestrict

type NumericRestrict struct {
	Namespace   string  `json:"namespace"`             // The numerical attribute name for the restriction.
	ValueFloat  float32 `json:"valueFloat,omitempty"`  // Floating-point value for comparison.
	ValueInt    int64   `json:"valueInt,omitempty"`    // Integer value for comparison.
	ValueDouble float64 `json:"valueDouble,omitempty"` // Double-precision floating-point value for comparison.
	Op          string  `json:"op,omitempty"`          // The comparison operator (e.g., "=", ">", "<=").
}

NumericRestrict represents a numerical filter for a specific namespace, allowing for range or exact matches.

type Restrict

type Restrict struct {
	Namespace string   `json:"namespace"`           // The category or attribute name for the restriction.
	AllowList []string `json:"allowList,omitempty"` // List of allowed values; if empty, all are allowed unless denied.
	DenyList  []string `json:"denyList,omitempty"`  // List of denied values; if empty, none are denied.
}

Restrict represents a categorical filter (allow or deny list) for a specific namespace.

type RetrieveParams

type RetrieveParams struct {
	Content           *ai.Document        // The query document to find similar documents for.
	Embedder          ai.Embedder         // The embedder used to vectorize the query content.
	EmbedderOptions   any                 // Optional settings for the query embedder.
	AuthClient        *google.Credentials // Authentication credentials for Google Cloud services.
	ProjectNumber     string              // The numeric ID of the Google Cloud project.
	Location          string              // The geographical region of the index endpoint.
	IndexEndpointID   string              // The ID of the specific index endpoint to query.
	PublicDomainName  string              // The public domain name of the deployed index within the endpoint.
	DeployedIndexID   string              // The ID of the deployed index within the endpoint.
	NeighborCount     int                 // The number of nearest neighbors to retrieve.
	Restricts         []Restrict          // Categorical restrictions to apply to the search.
	NumericRestricts  []NumericRestrict   // Numerical restrictions to apply to the search.
	DocumentRetriever DocumentRetriever   `json:"-"` // A function to retrieve original documents; excluded from JSON serialization.
}

RetrieveParams represents the parameters required for retrieving documents from a vector search index based on a query document.

type UpsertDatapointsParams

type UpsertDatapointsParams struct {
	Datapoints []IndexDatapoint // The slice of data points to upsert.
	ProjectID  string           // The Google Cloud Project ID.
	Location   string           // The geographical region of the index.
	IndexID    string           // The unique ID of the vector search index.
}

UpsertDatapointsParams represents the parameters required to add or update (upsert) multiple data points in a vector search index.

type VertexAIVectorSearch

type VertexAIVectorSearch struct {
	ProjectID string
	Location  string
	// contains filtered or unexported fields
}

func (*VertexAIVectorSearch) FindNeighbors

QueryPublicEndpoint queries a public index endpoint to find neighbors for a given feature vector.

func (*VertexAIVectorSearch) Init

Init initializes the VertexAI plugin and all known models and embedders. After calling Init, you may call [DefineModel] and [DefineEmbedder] to create and register any additional generative models and embedders

func (*VertexAIVectorSearch) Name

func (a *VertexAIVectorSearch) Name() string

func (*VertexAIVectorSearch) Retrieve

Retrieve retrieves documents from a Vertex AI index based on a query.

func (*VertexAIVectorSearch) UpsertDatapoints

func (v *VertexAIVectorSearch) UpsertDatapoints(params UpsertDatapointsParams) error

UpsertDatapoints upserts datapoints into a specified index.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL