Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions api/core/rag/datasource/vdb/vector_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class AbstractVectorFactory(ABC):
@abstractmethod
def init_vector(
self, dataset: Dataset, attributes: list, embeddings: Embeddings, *, session: Session | None
self, dataset: Dataset, attributes: list[str], embeddings: Embeddings, *, session: Session | None
) -> BaseVector:
"""Initialize the backend using the caller's session for metadata reads.

Expand Down Expand Up @@ -118,11 +118,21 @@ class Vector:
def __init__(
self,
dataset: Dataset,
attributes: list | None = None,
attributes: list[str] | None = None,
*,
session: Session | None,
vector_type: str | None = None,
):
embeddings: Embeddings | None = None,
) -> None:
"""Initialize this dataset's vector processor and embedding dependency.

``dataset`` must be loaded. ``attributes=None`` selects the default metadata projection;
``vector_type=None`` requires a session and resolves the backend from the dataset/configuration.
A supplied embedding adapter is used as-is; otherwise the dataset-backed lazy loader defers
model materialization until an embed method is called. On success, the selected factory has
initialized the processor with these dependencies. Raises ``ValueError`` when type resolution
needs a missing session; factory-loading errors propagate unchanged.
"""
if attributes is None:
# `is_summary` and `original_chunk_id` are stored on summary vectors
# by `SummaryIndexService` and read back by `RetrievalService` to
Expand All @@ -142,11 +152,10 @@ def __init__(
"original_chunk_id",
]
self._dataset = dataset
# Use a lazy proxy so cleanup paths (delete_by_ids / delete / text_exists)
# Use a lazy proxy by default so cleanup paths (delete_by_ids / delete / text_exists)
# never transitively trigger billing API calls during ``Vector(dataset, session=...)``
# construction. The real embedding model is materialized only when an
# ``embed_*`` method is actually invoked (i.e. create / search paths).
self._embeddings: Embeddings = _LazyEmbeddings(dataset)
# construction. An explicitly supplied adapter is retained without materializing a model.
self._embeddings: Embeddings = embeddings if embeddings is not None else _LazyEmbeddings(dataset)
self._attributes = attributes
self._session = session
if vector_type is not None:
Expand Down
2 changes: 1 addition & 1 deletion api/models/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class Dataset(TypeBase, kw_only=True):
)

@property
def index_struct_dict(self):
def index_struct_dict(self) -> dict[str, Any] | None:
return json.loads(self.index_struct) if self.index_struct else None

@property
Expand Down
Loading