Files
Averi Kitsch 017409785d vectorstore: Add interfaces for Google AlloyDB and Cloud SQL (#1204)
* feat(google): Add Google AlloyDB and Cloud SQL vectorstore and chat history

* vectorstore: Add interfaces for Google AlloyDB and Cloud SQL
2025-04-17 13:03:52 -07:00

93 lines
1.7 KiB
Go

package cloudsql
import "fmt"
type distanceStrategy interface {
String() string
operator() string
searchFunction() string
similaritySearchFunction() string
}
type Index interface {
Options() string
}
type Euclidean struct{}
func (Euclidean) String() string {
return "euclidean"
}
func (Euclidean) operator() string {
return "<->"
}
func (Euclidean) searchFunction() string {
return "vector_l2_ops"
}
func (Euclidean) similaritySearchFunction() string {
return "l2_distance"
}
type CosineDistance struct{}
func (CosineDistance) String() string {
return "cosineDistance"
}
func (CosineDistance) operator() string {
return "<=>"
}
func (CosineDistance) searchFunction() string {
return "vector_cosine_ops"
}
func (CosineDistance) similaritySearchFunction() string {
return "cosine_distance"
}
type InnerProduct struct{}
func (InnerProduct) String() string {
return "innerProduct"
}
func (InnerProduct) operator() string {
return "<#>"
}
func (InnerProduct) searchFunction() string {
return "vector_ip_ops"
}
func (InnerProduct) similaritySearchFunction() string {
return "inner_product"
}
// HNSWOptions holds the configuration for the hnsw index.
type HNSWOptions struct {
M int
EfConstruction int
}
func (h HNSWOptions) Options() string {
return fmt.Sprintf("(m = %d, ef_construction = %d)", h.M, h.EfConstruction)
}
// IVFFlatOptions holds the configuration for the ivfflat index.
type IVFFlatOptions struct {
Lists int
}
func (i IVFFlatOptions) Options() string {
return fmt.Sprintf("(lists = %d)", i.Lists)
}
// indexOptions returns the specific options for the index based on the index type.
func (index *BaseIndex) indexOptions() string {
return index.options.Options()
}