数据模型#
nlql.model —— 模态无关的数据模型:Payload / Document / Unit / Vector。从第一天起对文本 / 图像 / 二进制通用,Payload{modality} 携带模态标签。
model
#
Modality-agnostic data model: Payload, Document, Unit, Vector.
__all__
module-attribute
#
__all__ = ['Modality', 'Payload', 'Document', 'Unit', 'UnitKind', 'Span', 'Vector', 'as_array', 'normalize', 'to_list']
Document
dataclass
#
Document(id: str, payloads: list[Payload], metadata: dict[str, Any] = dict(), source: str | None = None)
A source document to be ingested.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
id
|
str
|
Stable, caller-provided identifier. Must be unique within a store. |
必需 |
payloads
|
list[Payload]
|
One or more content payloads (usually a single text payload). |
必需 |
metadata
|
dict[str, Any]
|
Opaque business metadata, addressed in queries via |
dict()
|
source
|
str | None
|
Optional provenance hint (file path, URL, …). |
None
|
Modality
#
Payload
dataclass
#
Payload(modality: Modality, data: str | bytes, mime: str | None = None)
Span
dataclass
#
Context-window info for kind="span" units.
Indices are positions within the parent document's ordered unit sequence (of the base granularity that was expanded), inclusive on both ends.
Unit
dataclass
#
Unit(id: str, doc_id: str, kind: UnitKind, payload: Payload, metadata: dict[str, Any] = dict(), vector: Vector | None = None, span: Span | None = None, scores: dict[str, float] = dict(), ordinal: int = 0, vectors: dict[str, Vector] = dict())
The atomic unit of retrieval and of results.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
id
|
str
|
Stable unit id (unique within a store). |
必需 |
doc_id
|
str
|
Owning document id. |
必需 |
kind
|
UnitKind
|
Granularity of this unit. |
必需 |
payload
|
Payload
|
The unit's content. |
必需 |
metadata
|
dict[str, Any]
|
Inherited business metadata from the document (read-only view). |
dict()
|
vector
|
Vector | None
|
Embedding, computed at ingestion; |
None
|
span
|
Span | None
|
Present when |
None
|
scores
|
dict[str, float]
|
Named scalar scores attached during query (e.g. |
dict()
|
ordinal
|
int
|
Position of this unit within its document's sequence, used for stable ordering and SPAN window expansion. |
0
|
metadata
class-attribute
instance-attribute
#
vectors
class-attribute
instance-attribute
#
vectors: dict[str, Vector] = field(default_factory=dict)
get_vector
#
get_vector(name: str = 'default') -> Vector | None
Return a named vector; "default" / "content" map to the primary vector.
A unit may carry several modality vectors (e.g. a text and an image vector),
queried separately via SIMILARITY(vec.<name>, "…").
源代码位于: src/nlql/model/unit.py
as_array
#
Coerce a sequence / array into a contiguous 1-D array of dtype.
源代码位于: src/nlql/model/vector.py
normalize
#
Return the unit-normalized vector; a zero vector is returned unchanged.