本文档是 xb/doc/CUSTOM_QUICKSTART.md 的中文版本。它引导你在不到 30 分钟内实现新适配器。
type MyVectorCustom struct {
Endpoint string
}
func NewMyVectorCustom(endpoint string) *MyVectorCustom {
return &MyVectorCustom{Endpoint: endpoint}
}
func (c *MyVectorCustom) Generate(built *xb.Built) (any, error) {
req := buildPayload(built) // 将条件转换为 JSON
return req, nil
}
WithCollection(name string)WithPayloadSelector(selector any)WithScoreThreshold(th float32)在你的自定义结构体上暴露辅助方法,以便调用者不接触原始字段。
func TestMyVectorCustom_Select(t *testing.T) {
built := xb.Of("vectors").
Eq("tenant_id", 42).
VectorSearch("embedding", xb.Vector{0.1, 0.2}, 5).
Build()
custom := NewMyVectorCustom("http://localhost:9000")
payload, err := custom.Generate(built)
require.NoError(t, err)
snapshot.AssertJSON(t, payload)
}
NewMyVectorCustom、MyVectorCustomHighPrecision)。JsonOfInsert/Update/Delete 的兼容性。doc/cn/CUSTOM_VECTOR_DB_GUIDE.md。