接口定义
ListCollection() 接口可查询指定 Base 类 Database 中所有的 Collection。
ListCollection(ctx context.Context) (result *tcvectordb.ListCollectionResult, err error)
使用示例
如下示例,查询数据库 go-sdk-test-db 下的集合配置。
var (ctx = context.Background()database = "go-sdk-test-db")db := client.Database(database)result, _ := db.ListCollection(ctx)for _, col := range result.Collections {data, _ := json.Marshal(col)log.Printf("%+v", string(data))}
出参描述
{"databaseName": "go-sdk-test-db","collectionName": "go-sdk-test-coll","documentCount": 0,"alias": null,"shardNum": 1,"replicasNum": 0,"indexes": {"VectorIndex": [{"FieldName": "vector","FieldType": "vector","ElemType": "","IndexType": "HNSW","Dimension": 3,"MetricType": "COSINE","IndexedCount": 0,"Params": {"M": 16,"EfConstruction": 200}}],"SparseVectorIndex": [{"FieldName": "sparse_vector","FieldType": "sparseVector","IndexType": "inverted","MetricType": "IP",}],"FilterIndex": [{"FieldName": "page","FieldType": "uint64","ElemType": "","IndexType": "filter"},{"FieldName": "id","FieldType": "string","ElemType": "","IndexType": "primaryKey"},{"FieldName": "bookName","FieldType": "string","ElemType": "","IndexType": "filter"},{"FieldName": "tag","FieldType": "array","ElemType": "","IndexType": "filter"}]},"indexStatus": {"Status": "ready","StartTime": "0001-01-01T00:00:00Z"},"embedding": {},"description": "test collection","createTime": "2023-12-20T17:26:12Z"}
参数 | 子参数 | 子参数 | 参数含义 |
databaseName | - | - | 显示 Collection 所在的 Database 名称。 |
collectionName | - | - | 显示 Collection 的名称。 |
replicaNum | - | - | 显示 Collection 的副本数。 |
shardNum | - | - | 显示 Collection 的分片数。 |
createTime | - | - | 显示 Collection 的创建时间。 |
description | - | - | 显示 Collection 的描述信息。 |
documentCount | - | - | 返回 Collection 中存储的 Document 数量。 |
indexes | VectorIndex | fieldName | 向量数据索引的字段名,固定为 vector。 |
| | filedType | vector 字段的数据类型,固定为 vector。 |
| | indexType | 显示索引类型。 |
| | indexedCount | 向量索引的文档数量。 |
| | dimension | 向量数据维度。 |
| | metricType | 目标向量数据与查询的向量数据相似性计算方法。 |
| | params | 向量索引类型对应的相关参数。 |
| FilterIndex | fieldName | id:默认对 id 构建主键 Filter 索引,对应 indexType 为 primaryKey。 page、bookName、tag:自定义扩展的设置为 Filter 表达式的字段名。 |
| | filedType | Filter 字段的数据类型。 |
| | indexType | fieldName 为 id,应 indexType 为 primaryKey。 其他为 Collection 配置的可以设置 Filter 表达式的字段,索引类型固定为 filter。 |
| SparseVectorIndex | fieldName | 稀疏向量字段名,固定为: sparse_vector 。 |
| | fieldType | 稀疏向量数据类型,固定为: sparseVector 。 |
| | indexType | 索引类型,固定为: inverted 。 |
| | metricType | 稀疏向量间的距离度量的算法。 |
embedding | - | status | 说明该 Collection 是否配置 Embedding 模型。 enabled:已配置。 disabled:未配置。 |
| | field | 显示 Embedding 模型输入文本的字段名。 |
| | model | Embedding 模型的名称。 |
| | vectorField | 显示 Embedding 模型向量字段名。 |
alias | - | - | 集合别名。 |
indexStatus | - | status | 标识当前 Collection 是否在重建索引。 ready:表示当前 Collection 已准备就绪,可正常使用。 training:表示当前 Collection 正在进行数据训练,即训练模型以生成向量数据。 building:表示当前 Collection 正在重建索引,即将生成的向量数据存储到新的索引中。 failed:重建索引失败,可能会影响集合读写操作。 |
| | startTime | 重建索引开始的时间。 |