WeaviateVectorStoreDataset¶
WeaviateVectorStoreDataset loads a handle for adding, searching, and deleting entries in Weaviate vector database collections.
kedro_datasets_experimental.weaviate.WeaviateVectorStoreDataset ¶
WeaviateVectorStoreDataset(
*,
collection_name,
connection_type="local",
url=None,
connection_params=None,
credentials=None,
create_collection_if_missing=True,
delete_batch_size=_DELETE_BY_ID_BATCH_SIZE,
metadata=None
)
Bases: AbstractVectorStoreDataset
Connect to a Weaviate collection and return a WeaviateVectorStoreHandle.
load() opens a connection to Weaviate, resolves (or creates) the target
collection, and returns a handle. All read/write operations go through the
handle. save() is intentionally disabled and raises DatasetError.
The handle owns the underlying gRPC connection; callers must close it::
with catalog.load("my_store") as store:
store.describe()
Three connection modes are supported, selected with connection_type:
"local"(default) — connects to a locally running Weaviate instance."cloud"— connects to Weaviate Cloud; requiresurl(cluster URL) and, typically,credentials: {api_key: ...}."custom"— passesconnection_paramsdirectly toweaviate.connect_to_custom()for self-hosted deployments with non-standard networking.
collection_name is a lookup key, not a schema definition. After
connecting, load() calls client.collections.get(collection_name)
to resolve the Weaviate collection
with that name on the server.
This dataset does not define or manage a collection's schema — its
properties, vectorizer, index config, and so on. That schema lives
entirely on the Weaviate side. Create it ahead of time (for example
through the Weaviate console, client, or REST API), or let load()
create it automatically. When create_collection_if_missing=True
(the default) and the collection doesn't exist, load() calls
client.collections.create(collection_name) with no schema
arguments. That produces an empty collection with Weaviate's default
auto-schema and no vectorizer configured.
That default is enough for add() with your own precomputed
vectors. search(text=...) needs a server-side vectorizer, and
custom property typing needs its own definition — both require
configuring the collection yourself first. See the
collections docs
for how to define one.
Examples:
Using the YAML API:
Local instance (default):
my_store:
type: weaviate.WeaviateVectorStoreDataset
collection_name: MyCollection
Weaviate Cloud:
my_store:
type: weaviate.WeaviateVectorStoreDataset
collection_name: MyCollection
connection_type: cloud
url: "https://my-cluster.weaviate.network"
credentials:
api_key: "${WEAVIATE_API_KEY}"
Self-hosted with custom networking:
my_store:
type: weaviate.WeaviateVectorStoreDataset
collection_name: MyCollection
connection_type: custom
connection_params:
http_host: my-host.internal
http_port: 8080
http_secure: false
grpc_host: my-host.internal
grpc_port: 50051
grpc_secure: false
Using the Python API:
>>> from kedro_datasets_experimental.weaviate import WeaviateVectorStoreDataset
>>> dataset = WeaviateVectorStoreDataset(collection_name="MyCollection")
>>> with dataset.load() as store:
... print(store.describe())
Parameters:
-
collection_name(str) –Name of the Weaviate collection to connect to.
-
connection_type(Literal['local', 'cloud', 'custom'], default:'local') –How to connect —
"local","cloud", or"custom". Defaults to"local". -
url(str | None, default:None) –For
"cloud": the Weaviate Cloud cluster URL (e.g."https://my-cluster.weaviate.network"). For"local": the host name (defaults to"localhost"). Ignored for"custom". -
connection_params(dict[str, Any] | None, default:None) –Extra keyword arguments forwarded to the underlying
weaviate.connect_to_*function. For"local": optional overrides such asportorgrpc_port. For"custom": all required networking parameters (http_host,http_port,grpc_host, etc.). -
credentials(dict[str, Any] | None, default:None) –Sensitive connection values, typically supplied through Kedro's credentials store. Recognised key:
"api_key"(used for"cloud"connections). -
create_collection_if_missing(bool, default:True) –When
True(default), the collection is created — with no explicit schema, i.e. Weaviate's default auto-schema and no vectorizer — if it does not already exist. WhenFalse,load()raises if the collection is absent. See the class docstring for when you need to define the collection's schema yourself instead of relying on this default. -
delete_batch_size(int, default:_DELETE_BY_ID_BATCH_SIZE) –Maximum number of IDs sent to Weaviate per call in
handle.delete(ids=...). Defaults to10,000, matching Weaviate's self-hosted defaultQUERY_MAXIMUM_RESULTS. Raise this (e.g. to100,000) for a Weaviate Cloud deployment, or lower it if your deployment hasQUERY_MAXIMUM_RESULTSconfigured below the default — seeWeaviateVectorStoreHandle.delete(). -
metadata(dict[str, Any] | None, default:None) –Arbitrary metadata passed through by Kedro; ignored by this dataset.
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
_create_collection_if_missing
instance-attribute
¶
_create_collection_if_missing = create_collection_if_missing
_connect ¶
_connect()
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
_describe ¶
_describe()
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
495 496 497 498 499 500 501 502 | |
_load ¶
_load()
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
kedro_datasets_experimental.weaviate.WeaviateVectorStoreHandle ¶
WeaviateVectorStoreHandle(
client,
collection,
delete_batch_size=_DELETE_BY_ID_BATCH_SIZE,
)
Bases: VectorStoreHandle
Handle for interacting with a Weaviate collection.
Returned by WeaviateVectorStoreDataset.load(). Owns the gRPC connection
to Weaviate; the connection must be closed after use, either by calling
close() explicitly or by using the handle as a context manager::
with catalog.load("my_store") as store:
store.describe()
This applies in every case, including when the handle is loaded as a
node input in a kedro run pipeline rather than through a hand-built
catalog as above. Kedro never closes it for you, and there's no way to
make it do so implicitly.
The Weaviate client opens a persistent HTTP connection pool and gRPC
channel on connect(). This lets repeated add()/search()/
delete() calls skip the TCP handshake, TLS negotiation, and version
handshake each time. Only close() tears both down.
Kedro's own cleanup hook, catalog.release(), operates on the
dataset object registered in the catalog, not on the handle object
that load() returns and that a node function receives. The dataset
doesn't keep a reference to the handles it hands out, so there's
nothing for release() to close even when it does run.
This dataset is atypical in that respect. Unlike a CSV or JSON
dataset, where load() returns inert data, this load() returns
a value that stays tethered to a live external connection.
If you receive this handle as a node input, close it — or wrap the
node body in a with block — inside that node function. That's the
only place with an unambiguous view of when the connection is
actually done being used.
The raw_client property exposes the underlying weaviate.WeaviateClient
for operations outside this interface.
Examples:
Using a hand-built catalog, with a context manager (recommended)::
>>> with catalog.load("my_store") as store:
... store.add([{"properties": {"text": "hello"}, "vector": [0.1, 0.2]}])
... store.search(vector=[0.1, 0.2], top_k=5)
>>> # store.close() has already run here, even if a call above raised.
Using a hand-built catalog, without a context manager::
>>> store = catalog.load("my_store")
>>> try:
... store.search(vector=[0.1, 0.2], top_k=5)
... finally:
... store.close() # Must close explicitly — nothing else will.
As a node input in a kedro run pipeline: Kedro loads the handle
and passes it to the node, but never closes it. The node itself
must do so::
def search_products(store: WeaviateVectorStoreHandle, query_vector: list[float]) -> list[dict]:
with store:
return store.search(vector=query_vector, top_k=5)
# Closed here on return, and also if search() raises.
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
98 99 100 101 102 103 104 105 106 107 | |
add ¶
add(records)
Insert records into the collection and return their UUIDs.
Each record is a plain dict with the following keys:
"properties"— the object's properties (dict)."vector"— the embedding (list[float]); optional when the collection has a server-side vectorizer configured."id"— an optional UUID string; Weaviate auto-generates one if absent.
Parameters:
-
records(list[dict[str, Any]]) –Records to insert.
Returns:
-
list[str]–List of UUID strings for the inserted objects, in the same order
-
list[str]–as the input records.
Raises:
-
DatasetError–If the batch insert call fails, or if Weaviate returns errors for one or more objects.
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
close ¶
close()
Close the gRPC connection. Safe to call more than once.
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
114 115 116 117 118 | |
delete ¶
delete(*, ids=None, filters=None)
Delete objects from the collection by ID or filter.
Exactly one of ids or filters must be provided.
Weaviate's server-side QUERY_MAXIMUM_RESULTS setting caps how
many objects a single batch delete can address (10,000 self-hosted
or 100,000 on Weaviate Cloud, by default). Both branches below
account for it, since a single call isn't guaranteed to remove
everything a large ids list or a broadly-matching filter
targets:
idsis split into chunks ofdelete_batch_size(set on the handle at construction time; defaults to 10,000), each deleted with its owncollection.data.delete_many(where=Filter.by_id().contains_any(...))call, rather than one round trip per ID.filtersis re-run withcollection.data.delete_many(where=filters)until it reports no more matches, since one call only deletes up to the server's limit even if more objects match.
Parameters:
-
ids(list[str] | None, default:None) –List of UUID strings to delete.
-
filters(Any, default:None) –A
weaviate.classes.query.Filterexpression that selects objects to delete.
Raises:
-
DatasetError–If neither or both arguments are supplied, if the deletion call to Weaviate fails, or if a
filtersdelete still reports matches after_DELETE_BY_FILTER_MAX_ITERATIONSre-runs.
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
describe ¶
describe()
Return collection name and current record count.
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
120 121 122 123 124 125 126 | |
search ¶
search(*, vector=None, text=None, top_k=10, filters=None)
Search the collection by vector or text and return the top matches.
Exactly one of vector or text must be provided. vector
triggers near_vector search; text triggers near_text
(requires a vectorizer configured on the collection).
Parameters:
-
vector(list[float] | None, default:None) –Query embedding for similarity search.
-
text(str | None, default:None) –Query string for near-text search.
-
top_k(int, default:10) –Maximum number of results to return. Defaults to 10. Capped by Weaviate's server-side
QUERY_MAXIMUM_RESULTSsetting (10,000 self-hosted or 100,000 on Weaviate Cloud, by default); atop_kabove that raisesDatasetErrorrather than paginating. -
filters(Any, default:None) –A
weaviate.classes.query.Filterexpression to restrict the search scope (passed directly to the underlying query).
Returns:
-
list[dict[str, Any]]–List of result dicts, each containing
"id"(UUID string), -
list[dict[str, Any]]–"properties"(dict of stored object properties), and -
list[dict[str, Any]]–"distance"(float).
Raises:
-
DatasetError–If neither or both of
vector/textare supplied, or if the query call to Weaviate fails.
Source code in kedro_datasets_experimental/weaviate/weaviate_vector_store_dataset.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |