From 03461121e2a098740fea3823afd3d7a71676d79f Mon Sep 17 00:00:00 2001 From: hansen Date: Wed, 27 Nov 2024 15:42:19 +0800 Subject: [PATCH] =?UTF-8?q?version1.1.10=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=90=91=E9=87=8F=E6=96=87=E6=9C=AC=E6=B7=B7=E5=90=88=E6=A3=80?= =?UTF-8?q?=E7=B4=A2,=E5=90=91=E9=87=8F=E7=BB=9F=E8=AE=A1=E8=AF=AD?= =?UTF-8?q?=E6=B3=95api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 332 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 319 insertions(+), 13 deletions(-) diff --git a/client/client.go b/client/client.go index c3f3f3d..8be8847 100644 --- a/client/client.go +++ b/client/client.go @@ -121,6 +121,8 @@ type QueryRequest struct { VectorCount *int `json:"vectorCount,omitempty" xml:"vectorCount,omitempty"` // 排序表达式 Sort *string `json:"sort,omitempty" xml:"sort,omitempty"` + // kvpairs + Kvpairs map[string]*string `json:"kvpairs,omitempty" xml:"kvpairs,omitempty"` } func (s QueryRequest) String() string { @@ -216,6 +218,11 @@ func (s *QueryRequest) SetSort(v string) *QueryRequest { return s } +func (s *QueryRequest) SetKvpairs(v map[string]*string) *QueryRequest { + s.Kvpairs = v + return s +} + type SparseData struct { // 每个稀疏向量中包含的元素个数 Count []*int `json:"count,omitempty" xml:"count,omitempty" type:"Repeated"` @@ -332,6 +339,8 @@ type FetchRequest struct { IncludeVector *bool `json:"includeVector,omitempty" xml:"includeVector,omitempty"` // 需要返回的字段,不指定默认返回所有的字段 OutputFields []*string `json:"outputFields,omitempty" xml:"outputFields,omitempty" type:"Repeated"` + // kvpairs + Kvpairs map[string]*string `json:"kvpairs,omitempty" xml:"kvpairs,omitempty"` } func (s FetchRequest) String() string { @@ -382,6 +391,262 @@ func (s *FetchRequest) SetOutputFields(v []*string) *FetchRequest { return s } +func (s *FetchRequest) SetKvpairs(v map[string]*string) *FetchRequest { + s.Kvpairs = v + return s +} + +type RankQuery struct { + // 查询表达式 + Rrf map[string]*string `json:"rrf,omitempty" xml:"rrf,omitempty"` +} + +func (s RankQuery) String() string { + return tea.Prettify(s) +} + +func (s RankQuery) GoString() string { + return s.String() +} + +func (s *RankQuery) SetRrf(v map[string]*string) *RankQuery { + s.Rrf = v + return s +} + +type TextQuery struct { + // ha3 query语法,支持多个文本索引的AND、OR嵌套 + QueryString *string `json:"queryString,omitempty" xml:"queryString,omitempty" require:"true"` + // query查询参数: + // + // default_op: 指定在该次查询中使用的默认query 分词后的连接操作符,AND or OR。默认为AND。 + // + // global_analyzer: 查询中指定全局的分词器,该分词器会覆盖schema的分词器,指定的值必须在analyzer.json里有配置。 + // + // specific_index_analyzer: 查询中指定index使用另外的分词器,该分词器会覆盖global_analyzer和schema的分词器。 + // + // no_token_indexes: 支持查询中指定的index不分词(除分词以外的其他流程如归一化、去停用词会正常执行),多个index之间用;分割。 + // + // remove_stopwords: true or false 表示是否需要删除stop words,stop words在分词器中配置。默认true + QueryParams map[string]*string `json:"queryParams,omitempty" xml:"queryParams,omitempty"` + // 过滤条件表达式 + Filter *string `json:"filter,omitempty" xml:"filter,omitempty"` + // text查询结果的权重,以score - weight的结果作为该路的排序分 + Weight *float32 `json:"weight,omitempty" xml:"weight,omitempty"` + // 每个分片查找满足条件的文档的最大数量。到达这个数量后,查询将提前结束,不再继续查询索引。默认为0,不设置限制。 + TerminateAfter *int `json:"terminateAfter,omitempty" xml:"terminateAfter,omitempty"` +} + +func (s TextQuery) String() string { + return tea.Prettify(s) +} + +func (s TextQuery) GoString() string { + return s.String() +} + +func (s *TextQuery) SetQueryString(v string) *TextQuery { + s.QueryString = &v + return s +} + +func (s *TextQuery) SetQueryParams(v map[string]*string) *TextQuery { + s.QueryParams = v + return s +} + +func (s *TextQuery) SetFilter(v string) *TextQuery { + s.Filter = &v + return s +} + +func (s *TextQuery) SetWeight(v float32) *TextQuery { + s.Weight = &v + return s +} + +func (s *TextQuery) SetTerminateAfter(v int) *TextQuery { + s.TerminateAfter = &v + return s +} + +type SearchRequest struct { + // 数据源名 + TableName *string `json:"tableName,omitempty" xml:"tableName,omitempty" require:"true"` + // 返回结果的个数 + Size *int `json:"size,omitempty" xml:"size,omitempty"` + // 从结果集的第from返回doc + From *int `json:"from,omitempty" xml:"from,omitempty"` + // 结果排序方向:DESC: 降序排序;ASC: 升序排序 + Order *string `json:"order,omitempty" xml:"order,omitempty"` + // 指定需要在结果中返回的字段,默认为空 + OutputFields []*string `json:"outputFields,omitempty" xml:"outputFields,omitempty" type:"Repeated"` + // KNN查询参数 + Knn *QueryRequest `json:"knnQuery,omitempty" xml:"knnQuery,omitempty"` + // text查询参数 + Text *TextQuery `json:"textQuery,omitempty" xml:"textQuery,omitempty"` + // 指定两路结果融合的方式,目前支持两种策略:默认策略:两路结果中相同pk的doc的分数按权重相加。按加权后的分数排序。rrf: 使用rrf融合两路结果 + Rank *RankQuery `json:"rankQuery,omitempty" xml:"rankQuery,omitempty"` +} + +func (s SearchRequest) String() string { + return tea.Prettify(s) +} + +func (s SearchRequest) GoString() string { + return s.String() +} + +func (s *SearchRequest) SetTableName(v string) *SearchRequest { + s.TableName = &v + return s +} + +func (s *SearchRequest) SetSize(v int) *SearchRequest { + s.Size = &v + return s +} + +func (s *SearchRequest) SetFrom(v int) *SearchRequest { + s.From = &v + return s +} + +func (s *SearchRequest) SetOrder(v string) *SearchRequest { + s.Order = &v + return s +} + +func (s *SearchRequest) SetOutputFields(v []*string) *SearchRequest { + s.OutputFields = v + return s +} + +func (s *SearchRequest) SetKnn(v *QueryRequest) *SearchRequest { + s.Knn = v + return s +} + +func (s *SearchRequest) SetText(v *TextQuery) *SearchRequest { + s.Text = v + return s +} + +func (s *SearchRequest) SetRank(v *RankQuery) *SearchRequest { + s.Rank = v + return s +} + +type AggFuncDesc struct { + // 可以指定统计值在结果集中字段的名称。默认结果字段为: FUNC_NAME(args) + Name *string `json:"name,omitempty" xml:"name,omitempty"` + // 统计函数名:max, min, avg, sum, count + Func *string `json:"func,omitempty" xml:"func,omitempty" require:"true"` + // 统计函数的参数 + Args []*string `json:"args,omitempty" xml:"args,omitempty" require:"true" type:"Repeated"` +} + +func (s AggFuncDesc) String() string { + return tea.Prettify(s) +} + +func (s AggFuncDesc) GoString() string { + return s.String() +} + +func (s *AggFuncDesc) SetName(v string) *AggFuncDesc { + s.Name = &v + return s +} + +func (s *AggFuncDesc) SetFunc(v string) *AggFuncDesc { + s.Func = &v + return s +} + +func (s *AggFuncDesc) SetArgs(v []*string) *AggFuncDesc { + s.Args = v + return s +} + +type OrderByDesc struct { + // 排序字段名称,必须指定结果集中的字段 + Field *string `json:"field,omitempty" xml:"field,omitempty" require:"true"` + // 排序方向,DESC: 降序排列;ASC: 升序排列 + Direction *string `json:"direction,omitempty" xml:"direction,omitempty"` +} + +func (s OrderByDesc) String() string { + return tea.Prettify(s) +} + +func (s OrderByDesc) GoString() string { + return s.String() +} + +func (s *OrderByDesc) SetField(v string) *OrderByDesc { + s.Field = &v + return s +} + +func (s *OrderByDesc) SetDirection(v string) *OrderByDesc { + s.Direction = &v + return s +} + +type AggregateRequest struct { + // 需要统计的表名 + TableName *string `json:"tableName,omitempty" xml:"tableName,omitempty" require:"true"` + // 过滤条件 + Filter *string `json:"filter,omitempty" xml:"filter,omitempty"` + // 分组统计的字段列表 + GroupKeys []*string `json:"groupKeys,omitempty" xml:"groupKeys,omitempty" type:"Repeated"` + // 统计函数列表 + AggFuncs []*AggFuncDesc `json:"aggFuncs,omitempty" xml:"aggFuncs,omitempty" require:"true" type:"Repeated"` + // 统计结果排序方式,支持多维排序 + OrderBy []*OrderByDesc `json:"orderBy,omitempty" xml:"orderBy,omitempty" type:"Repeated"` + // 超时时间,单位毫秒 + Timeout *int `json:"timeout,omitempty" xml:"timeout,omitempty"` +} + +func (s AggregateRequest) String() string { + return tea.Prettify(s) +} + +func (s AggregateRequest) GoString() string { + return s.String() +} + +func (s *AggregateRequest) SetTableName(v string) *AggregateRequest { + s.TableName = &v + return s +} + +func (s *AggregateRequest) SetFilter(v string) *AggregateRequest { + s.Filter = &v + return s +} + +func (s *AggregateRequest) SetGroupKeys(v []*string) *AggregateRequest { + s.GroupKeys = v + return s +} + +func (s *AggregateRequest) SetAggFuncs(v []*AggFuncDesc) *AggregateRequest { + s.AggFuncs = v + return s +} + +func (s *AggregateRequest) SetOrderBy(v []*OrderByDesc) *AggregateRequest { + s.OrderBy = v + return s +} + +func (s *AggregateRequest) SetTimeout(v int) *AggregateRequest { + s.Timeout = &v + return s +} + type PushDocumentsRequest struct { // headers Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` @@ -596,7 +861,7 @@ func (client *Client) _request(method *string, pathname *string, query map[strin // Description: -// +// // 如果endpoint 配置以 http:// 或 https:// 开头,则去掉头部的 http:// 或 https://, 否则直接返回 func (client *Client) GetEndpoint (endpoint *string) (_result *string) { if tea.BoolValue(string_.HasPrefix(endpoint, tea.String("http://"))) { @@ -616,21 +881,21 @@ func (client *Client) GetEndpoint (endpoint *string) (_result *string) { } // Description: -// +// // 设置Client UA 配置. func (client *Client) SetUserAgent (userAgent *string) { client.UserAgent = userAgent } // Description: -// +// // 添加Client UA 配置. func (client *Client) AppendUserAgent (userAgent *string) { client.UserAgent = tea.String(tea.StringValue(client.UserAgent) + " " + tea.StringValue(userAgent)) } // Description: -// +// // 获取Client 配置 UA 配置. func (client *Client) GetUserAgent () (_result *string) { userAgent := util.GetUserAgent(client.UserAgent) @@ -639,7 +904,7 @@ func (client *Client) GetUserAgent () (_result *string) { } // Description: -// +// // 计算用户请求识别特征, 遵循 Basic Auth 生成规范. func (client *Client) GetRealmSignStr (accessUserName *string, accessPassWord *string) (_result *string) { accessUserNameStr := string_.Trim(accessUserName) @@ -651,7 +916,7 @@ func (client *Client) GetRealmSignStr (accessUserName *string, accessPassWord *s } // Description: -// +// // 向量查询 func (client *Client) Query (request *QueryRequest) (_result *SearchResponse, _err error) { _result = &SearchResponse{} @@ -664,7 +929,7 @@ func (client *Client) Query (request *QueryRequest) (_result *SearchResponse, _e } // Description: -// +// // 向量预测查询 func (client *Client) InferenceQuery (request *QueryRequest) (_result *SearchResponse, _err error) { _result = &SearchResponse{} @@ -677,7 +942,7 @@ func (client *Client) InferenceQuery (request *QueryRequest) (_result *SearchRes } // Description: -// +// // 多namespace查询 func (client *Client) MultiQuery (request *MultiQueryRequest) (_result *SearchResponse, _err error) { _result = &SearchResponse{} @@ -690,7 +955,7 @@ func (client *Client) MultiQuery (request *MultiQueryRequest) (_result *SearchRe } // Description: -// +// // 查询数据 func (client *Client) Fetch (request *FetchRequest) (_result *SearchResponse, _err error) { _result = &SearchResponse{} @@ -703,7 +968,33 @@ func (client *Client) Fetch (request *FetchRequest) (_result *SearchResponse, _e } // Description: -// +// +// 文本向量混合检索 +func (client *Client) Search (request *SearchRequest) (_result *SearchResponse, _err error) { + _result = &SearchResponse{} + _body, _err := client._request(tea.String("POST"), tea.String("/vector-service/search"), nil, nil, util.ToJSONString(request), client.RuntimeOptions) + if _err != nil { + return _result, _err + } + _err = tea.Convert(_body, &_result) + return _result, _err +} + +// Description: +// +// 向量引擎统计语法 +func (client *Client) Aggregate (request *AggregateRequest) (_result *SearchResponse, _err error) { + _result = &SearchResponse{} + _body, _err := client._request(tea.String("POST"), tea.String("/vector-service/aggregate"), nil, nil, util.ToJSONString(request), client.RuntimeOptions) + if _err != nil { + return _result, _err + } + _err = tea.Convert(_body, &_result) + return _result, _err +} + +// Description: +// // 文档统计 func (client *Client) Stats (tableName *string) (_result *SearchResponse, _err error) { body := map[string]interface{}{ @@ -719,7 +1010,22 @@ func (client *Client) Stats (tableName *string) (_result *SearchResponse, _err e } // Description: -// +// +// 校验网络是否通畅 +// +// 检查vpc & 用户名密码配置是否正确 +func (client *Client) Active () (_result *SearchResponse, _err error) { + _result = &SearchResponse{} + _body, _err := client._request(tea.String("GET"), tea.String("/network/active"), nil, nil, nil, client.RuntimeOptions) + if _err != nil { + return _result, _err + } + _err = tea.Convert(_body, &_result) + return _result, _err +} + +// Description: +// // 支持新增、更新、删除 等操作,以及对应批量操作 func (client *Client) PushDocuments (dataSourceName *string, keyField *string, request *PushDocumentsRequest) (_result *PushDocumentsResponse, _err error) { request.Headers = tea.Merge(map[string]*string{ @@ -735,7 +1041,7 @@ func (client *Client) PushDocuments (dataSourceName *string, keyField *string, r } // Description: -// +// // 用于内网环境的新增、更新、删除 等操作,以及对应批量操作 func (client *Client) PushDocumentsWithSwift (dataSourceName *string, keyField *string, topic *string, swift *string, request *PushDocumentsRequest) (_result *PushDocumentsResponse, _err error) { request.Headers = map[string]*string{ @@ -753,7 +1059,7 @@ func (client *Client) PushDocumentsWithSwift (dataSourceName *string, keyField * } // Description: -// +// // 构建RuntimeOptions func (client *Client) BuildRuntimeOptions (runtimeOptions *util.RuntimeOptions) (_result *util.RuntimeOptions) { if tea.BoolValue(util.IsUnset(runtimeOptions)) {