DashVector utiliza los siguientes tipos de datos para representar documentos, colecciones y sus estados. Esta página proporciona las definiciones en Python y Java para cada tipo.
Doc
Un elemento Doc es un registro individual dentro de una colección de DashVector. Este asocia un vector con un identificador y metadatos opcionales:
{
"id": "doc-001",
"vector": [0.1, 0.2, 0.3, 0.4],
"sparse_vector": {"10": 0.5, "25": 0.8},
"fields": {"category": "article", "year": 2024},
"score": 0.95
}
Python
@dataclass(frozen=True)
class Doc(object):
id: str # The primary key.
vector: Union[List[int], List[float], np.ndarray] # The vector.
sparse_vector: Optional[Dict[int, float]] = None # The sparse vector.
fields: Optional[FieldDataDict] = None # The custom fields in the document.
score: float = 0.0 # The similarity between vectors.
Java
@Data
@Builder
public class Doc {
// The primary key.
@NonNull private String id;
// The vector.
@NonNull private Vector vector;
// The sparse vector.
private TreeMap<Integer, Float> sparseVector;
// The custom fields in the document.
@Builder.Default private Map<String, Object> fields = new HashMap<>();
// The similarity between vectors.
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);
}
}
Referencia de campos
|
Campo |
Tipo (Python) |
Tipo (Java) |
Descripción |
|
|
|
|
Clave primaria que identifica de forma única un documento. |
|
|
|
|
Vector denso. |
|
|
|
|
Vector disperso. |
|
|
|
|
Pares clave-valor personalizados para el filtrado de metadatos. |
|
|
|
|
Similitud entre vectores. |
Tipos de datos de campo compatibles
|
Tipo |
Python |
Java |
|
String |
|
|
|
Integer |
|
|
|
Float |
|
|
|
Boolean |
|
|
CollectionMeta
El objeto CollectionMeta describe la configuración de una colección: su nombre, las dimensiones del vector, la métrica de distancia, el esquema de campos y la distribución de particiones.
Python
@dataclass(frozen=True)
class CollectionMeta(object):
name: str # The name of the collection.
dimension: int # The number of vector dimensions.
dtype: str # The data type of the vector. Valid values: float and int.
metric: str # The distance metric. Valid values: euclidean, dotproduct, and cosine.
status: Status # The status of the collection.
fields: Dict[str, str] # The fields in the collection. Supported data types of fields: float, bool, int, and str.
partitions: Dict[str, Status] # The information about the partitions in the collection.
Java
@Getter
public class CollectionMeta {
// The name of the collection.
private final String name;
// The number of vector dimensions.
private final int dimension;
// The data type of the vector. Valid values: float and int.
private final CollectionInfo.DataType dataType;
// The distance metric. Valid values: euclidean, dotproduct, and cosine.
private final CollectionInfo.Metric metric;
// The status of the collection.
private final String status;
// The fields in the collection. Supported data types of fields: float, bool, int, and str.
private final Map<String, FieldType> fieldsSchema;
// The information about the partitions in the collection.
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();
}
}
Referencia de campos
|
Campo |
Tipo (Python) |
Tipo (Java) |
Descripción |
|
|
|
|
Nombre de la colección. |
|
|
|
|
Número de dimensiones del vector. |
|
|
|
|
Tipo de datos de los vectores en la colección. Valores válidos: |
|
|
|
|
Métrica de distancia para la búsqueda por similitud. Valores válidos: |
|
|
|
|
Estado actual de la colección. Consulte Status. |
|
|
|
|
Esquema de los campos personalizados definidos para la colección. Tipos de datos compatibles: |
|
|
|
|
Asignación de los nombres de partición a su estado actual. |
Métricas de distancia
|
Métrica |
Valor de API |
|
Distancia euclidiana |
|
|
Producto punto |
|
|
Similitud coseno |
|
Tipos de datos de vector
|
Tipo de datos |
Valor de API |
|
Float |
|
|
Integer |
|
CollectionStats
El objeto CollectionStats reporta la cantidad de documentos y el progreso de compilación del índice de una colección.
Python
@dataclass(frozen=True)
class CollectionStats(object):
total_doc_count: int # The total number of documents inserted into the collection.
index_completeness: float # The completeness of data insertion into the collection.
partitions: Dict[str, PartitionStats] # The information about the partitions in the collection.
Java
@Getter
public class CollectionStats {
// The total number of documents inserted into the collection.
private final long totalDocCount;
// The completeness of data insertion into the collection.
private final float indexCompleteness;
// The information about the partitions in the collection.
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)));
}
}
Referencia de campos
|
Campo |
Tipo (Python) |
Tipo (Java) |
Descripción |
|
|
|
|
Cantidad total de documentos insertados en la colección. |
|
|
|
|
Nivel de completitud de la inserción de datos en la colección. |
|
|
|
|
Asignación de los nombres de partición a sus estadísticas. Consulte PartitionStats. |
PartitionStats
El objeto PartitionStats reporta la cantidad de documentos de una sola partición dentro de una colección.
Python
@dataclass(frozen=True)
class PartitionStats(object):
total_doc_count: int # The total number of documents in the partition.
Java
@Getter
public class PartitionStats {
// The total number of documents in the partition.
private final long totalDocCount;
public PartitionStats(com.aliyun.dashvector.proto.PartitionStats partitionStats) {
this.totalDocCount = partitionStats.getTotalDocCount();
}
}
Referencia de campos
|
Campo |
Tipo (Python) |
Tipo (Java) |
Descripción |
|
|
|
|
Cantidad total de documentos en la partición. |
Status
La enumeración Status define los estados del ciclo de vida de una colección o partición.
class Status(IntEnum):
INITIALIZED = 0 # The collection or partition is being created.
SERVING = 1 # The collection or partition is in service.
DROPPING = 2 # The collection or partition is being deleted.
ERROR = 3 # The collection or partition is abnormal.
|
Valor |
Entero |
Descripción |
|
|
0 |
La colección o partición se está creando. |
|
|
1 |
La colección o partición está en servicio. |
|
|
2 |
La colección o partición se está eliminando. |
|
|
3 |
La colección o partición presentó un error. |
Alias de tipos (Python)
El SDK de Python define los siguientes alias de tipos:
long = NewType("long", int)
FieldDataType = Union[long, str, int, float, bool]
FieldDataDict = Dict[str, FieldDataType]
VectorValueType = Union[List[int], List[float], np.ndarray]
|
Alias |
Definición |
Descripción |
|
|
|
Tipo entero extendido. |
|
|
|
Tipos de valores aceptados para los campos personalizados del documento. |
|
|
|
Tipo del parámetro |
|
|
|
Tipos aceptados para el parámetro |