このトピックでは、DashVector のデータ型について説明します。
Doc
@dataclass(frozen=True)
class Doc(object):
id: str # 主キー。
vector: Union[List[int], List[float], np.ndarray] # ベクトル。
sparse_vector: Optional[Dict[int, float]] = None # スパースベクトル。
fields: Optional[FieldDataType] = None # ドキュメント内のカスタムフィールド。
score: float = 0.0 # ベクトル間の類似度。@Data
@Builder
public class Doc {
// 主キー。
@NonNull private String id;
// ベクトル。
@NonNull private Vector vector;
// スパースベクトル。
private TreeMap<Integer, Float> sparseVector;
// ドキュメント内のカスタムフィールド。
@Builder.Default private Map<String, Object> fields = new HashMap<>();
// ベクトル間の類似度。
private float score;
public void addField(String key, String value) {
this.fields.put(key, value);
}
public void addField(String key, Integer value) {
this.fields.put(key, value);
}
public void addField(String key, Float value) {
this.fields.put(key, value);
}
public void addField(String key, Boolean value) {
this.fields.put(key, value);
}
}CollectionMeta
@dataclass(frozen=True)
class CollectionMeta(object):
name: str # コレクションの名前。
dimension: int # ベクトルの次元数。
dtype: str # ベクトルのデータ型。有効な値: float および int。
metric: str # 距離メトリック。有効な値: euclidean、dotproduct、および cosine。
status: Status # コレクションのステータス。
fields: Dict[str, str] # コレクション内のフィールド。サポートされているフィールドのデータ型: float、bool、int、および str。
partitions: Dict[str, Status] # コレクション内のパーティションに関する情報。@Getter
public class CollectionMeta {
// コレクションの名前。
private final String name;
// ベクトルの次元数。
private final int dimension;
// ベクトルのデータ型。有効な値: float および int。
private final CollectionInfo.DataType dataType;
// 距離メトリック。有効な値: euclidean、dotproduct、および cosine。
private final CollectionInfo.Metric metric;
// コレクションのステータス。
private final String status;
// コレクション内のフィールド。サポートされているフィールドのデータ型: float、bool、int、および str。
private final Map<String, FieldType> fieldsSchema;
// コレクション内のパーティションに関する情報。
private final Map<String, Status> partitionStatus;
public CollectionMeta(CollectionInfo collectionInfo) {
this.name = collectionInfo.getName();
this.dimension = collectionInfo.getDimension();
this.dataType = collectionInfo.getDtype();
this.metric = collectionInfo.getMetric();
this.status = collectionInfo.getStatus().name();
this.fieldsSchema = collectionInfo.getFieldsSchemaMap();
this.partitionStatus = collectionInfo.getPartitionsMap();
}
}
CollectionStats
@dataclass(frozen=True)
class CollectionStats(object):
total_doc_count: int # コレクションに挿入されたドキュメントの総数。
index_completeness: float # コレクションへのデータ挿入の完了率。
partitions: Dict[str, PartitionStats] # コレクション内のパーティションに関する情報。@Getter
public class CollectionStats {
// コレクションに挿入されたドキュメントの総数。
private final long totalDocCount;
// コレクションへのデータ挿入の完了率。
private final float indexCompleteness;
// コレクション内のパーティションに関する情報。
private final Map<String, PartitionStats> partitions;
public CollectionStats(StatsCollectionResponse.CollectionStats collectionStats) {
this.totalDocCount = collectionStats.getTotalDocCount();
this.indexCompleteness = collectionStats.getIndexCompleteness();
this.partitions = new HashMap<>();
collectionStats
.getPartitionsMap()
.forEach((key, value) -> this.partitions.put(key, new PartitionStats(value)));
}
}PartitionStats
@dataclass(frozen=True)
class PartitionStats(object):
total_doc_count: int # パーティション内のドキュメントの総数。@Getter
public class PartitionStats {
// パーティション内のドキュメントの総数。
private final long totalDocCount;
public PartitionStats(com.aliyun.dashvector.proto.PartitionStats partitionStats) {
this.totalDocCount = partitionStats.getTotalDocCount();
}
}
Status
class Status(IntEnum):
INITIALIZED = 0 # コレクションまたはパーティションは作成中です。
SERVING = 1 # コレクションまたはパーティションはサービス中です。
DROPPING = 2 # コレクションまたはパーティションは削除中です。
ERROR = 3 # コレクションまたはパーティションは異常です。Others
FieldDataType = Dict[str, Union[Type[str], Type[int], Type[float], Type[bool]]]