FAISSVectorStoreDataset¶
FAISSVectorStoreDataset loads a handle for adding, searching, and deleting entries in a FAISS vector store.
kedro_datasets_experimental.faiss.FAISSVectorStoreDataset ¶
FAISSVectorStoreDataset(
*,
dimension,
index_path=None,
index_factory="Flat",
metric="l2",
metadata=None
)
Bases: AbstractVectorStoreDataset
Connect to a FAISS index and return a FAISSVectorStoreHandle.
Unlike weaviate.WeaviateVectorStoreDataset/chromadb.ChromaDBDataset,
FAISS is a pure numerical index library — no server, no client, no
metadata storage, no persistence beyond raw index files, no embedding
function. This dataset and its handle build the ID-mapping, metadata
side-store, and persistence machinery themselves, and deliberately expose
more of the library directly than the other two backends do: users who
reach for FAISS specifically want a less-abstracted, hands-on experience.
load() creates or hydrates a FAISS index (wrapped in an IndexIDMap for
string-ID support) and returns a handle. All read/write operations go
through the handle. save() is intentionally disabled on the dataset and
raises DatasetError — persistence goes through handle.save(), called
explicitly, never automatically.
index_path is optional. If given and both the index file and its
f"{index_path}.meta.json" sidecar exist, load() hydrates from disk. If
given but absent, load() starts a fresh index (nothing is written until
handle.save() is called). If omitted entirely, the handle is pure
in-memory — data does not survive past the handle's lifetime unless
handle.save(path=...) is called with an explicit path.
index_factory is passed straight to FAISS's own index_factory() —
"Flat" (the default) is exact search and needs no training. Clustering-
based approximate types like "IVF100,Flat" need handle.train() called
before add(), since they need to see representative data before they can
decide where to put cluster boundaries. Graph-based types like "HNSW32"
build incrementally as vectors are added and need no training step at all
— check handle.raw_client.is_trained if you're unsure whether a given
index_factory choice needs one.
Examples:
Using the YAML API:
my_index:
type: faiss.FAISSVectorStoreDataset
dimension: 384
index_path: data/06_models/my_index.faiss
Using the Python API:
>>> from kedro_datasets_experimental.faiss import FAISSVectorStoreDataset
>>> dataset = FAISSVectorStoreDataset(dimension=3)
>>> with dataset.load() as store:
... ids = store.add(
... [{"properties": {"text": "hello"}, "vector": [0.1, 0.2, 0.3]}]
... )
... hits = store.search(vector=[0.1, 0.2, 0.3], top_k=5)
... store.save(path="/tmp/my_index.faiss")
Parameters:
-
dimension(int) –Dimensionality of the vectors to store. Always required — FAISS cannot create an index without it, and there is no reliable way to infer it before the first
add()call. -
index_path(str | None, default:None) –Path to persist to/hydrate from. See the class docstring for the three cases (hydrate / fresh-at-path / pure in-memory). Local filesystem only — no
fsspecsupport. -
index_factory(str, default:'Flat') –FAISS index factory string, e.g.
"Flat"(default, exact search, no training needed),"IVF100,Flat"(approximate, clustering-based, requireshandle.train()first), or"HNSW32"(approximate, graph-based, no training needed). -
metric(Literal['l2', 'ip'], default:'l2') –"l2"(default) or"ip"(inner product). No built-in cosine similarity — normalize vectors yourself and use"ip"if that's what you want, the standard FAISS convention. -
metadata(dict[str, Any] | None, default:None) –Arbitrary metadata passed through by Kedro; ignored by this dataset.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
_describe ¶
_describe()
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
552 553 554 555 556 557 558 | |
_load ¶
_load()
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
kedro_datasets_experimental.faiss.FAISSVectorStoreHandle ¶
FAISSVectorStoreHandle(
index,
index_path,
next_id=0,
id_to_internal=None,
properties=None,
)
Bases: VectorStoreHandle
Handle for interacting with a FAISS index.
Returned by FAISSVectorStoreDataset.load(). Unlike the Weaviate/Chroma
handles, this one owns no live connection — FAISS is a local, in-process
library, not a client/server. It also owns machinery those backends get
for free from their client libraries: FAISS itself only stores vectors and
int64 IDs, so this handle maintains its own string-ID mapping and a
properties side-store, and is responsible for its own persistence.
Persistence is deliberately explicit, not automatic: add()/delete()
never write to disk, and close() is a no-op that does not persist
anything. Call save() yourself when you want the current state written
out::
with catalog.load("my_index") as store:
store.add([{"properties": {"text": "hello"}, "vector": [0.1, 0.2]}])
store.save()
train() is required before add() for index_factory choices that need
training (e.g. "IVF100,Flat"); the default "Flat" never needs it.
raw_client exposes the underlying FAISS IndexIDMap-wrapped index for
anything not covered by this interface.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
_internal_to_id
instance-attribute
¶
_internal_to_id = {
internal_id: str_id
for str_id, internal_id in (
self._id_to_internal.items()
)
}
add ¶
add(records)
Insert records into the index and return their IDs.
Every record must carry a "vector" — FAISS has no embedding function
to fall back on. Records whose explicit "id" already exists in the
index, or that collide with another record's "id" in the same batch,
are rejected all-or-nothing: nothing is written if any collision is
found.
Parameters:
-
records(list[dict[str, Any]]) –Each record is a dict with keys
"properties"(dict, optional),"vector"(list[float], required),"id"(str, optional — generated if omitted).
Returns:
-
list[str]–List of ID strings for the inserted records, in input order.
Raises:
-
DatasetError–If the index isn't trained yet, if any record is missing
"vector", if any ID collides, if the batch's vectors aren't uniform in length, or if the underlying FAISS call fails.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 167 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 | |
close ¶
close()
No-op. FAISS is a local object, not a live connection — there is
nothing to release. This does not persist anything; call save()
explicitly if you want your data to survive past this handle's
lifetime.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
75 76 77 78 79 80 | |
delete ¶
delete(*, ids=None, filters=None)
Delete records from the index by ID or metadata predicate.
Exactly one of ids or filters must be provided.
Parameters:
-
ids(list[str] | None, default:None) –List of ID strings to delete. IDs that aren't present are silently skipped (no error).
-
filters(Callable[[dict[str, Any]], bool] | None, default:None) –A callable
(properties: dict) -> boolevaluated against every stored record's properties; matching records are deleted. This is an O(n) linear scan over the in-memory properties store — FAISS has no native metadata index to push this down to.
Raises:
-
DatasetError–If neither or both arguments are supplied, if
filtersraises while evaluating a record's properties, or if the underlying FAISS call fails.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
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 232 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 | |
describe ¶
describe()
Return the configured path (or "<in-memory>") and current record count.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
82 83 84 85 86 87 | |
save ¶
save(path=None)
Write the index and its metadata sidecar to disk.
The only persistence trigger — never called implicitly by
add(), delete(), or close(). Behaves like a thin wrapper around
what you'd do by hand with raw_client + faiss.write_index(): no
remembered path (path= here doesn't change what a later bare
save() defaults to), silent overwrite, local filesystem only.
The one addition beyond a literal passthrough: the index file is
written via a temp-file-then-os.replace() swap, so a crash mid-write
can't corrupt a previously-good file. The index file and the metadata
sidecar (f"{path}.meta.json") are still two separate writes — a
crash between them leaves the two out of sync; this is not solved,
just avoided for the index file itself.
Parameters:
-
path(str | None, default:None) –Where to write the index (and
f"{path}.meta.json"for the sidecar). Defaults to theindex_pathpassed to the dataset's constructor.
Raises:
-
DatasetError–If neither
pathnor a constructorindex_pathis set, or if either write fails.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
search ¶
search(*, vector=None, text=None, top_k=10, filters=None)
Search the index by vector and return the top matches.
text=... is never supported — FAISS has no embedding function, ever
(unlike Chroma, which has an optional default one).
Parameters:
-
vector(list[float] | None, default:None) –Query embedding for similarity search. Required (the only supported search mode).
-
text(str | None, default:None) –Not supported; always raises
NotImplementedErrorif given. -
top_k(int, default:10) –Maximum number of results to return. Defaults to 10.
-
filters(Callable[[dict[str, Any]], bool] | None, default:None) –A callable
(properties: dict) -> boolrestricting the search to matching records. Evaluated as an O(n) linear scan over the properties store, then pushed into FAISS's own search via anIDSelector(not applied as post-filtering on the results, which would under-count matches).
Returns:
-
list[dict[str, Any]]–List of result dicts, each containing
"id"(str),"properties" -
list[dict[str, Any]]–(dict), and
"distance"(float).
Raises:
-
NotImplementedError–If
textis given. -
DatasetError–If neither or both of
vector/textare supplied, iffiltersraises while evaluating a record's properties, or if the underlying FAISS call fails.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
train ¶
train(vectors)
Train the underlying FAISS index.
Required before add() for index_factory choices that need training
(e.g. "IVF100,Flat"). Not needed for "Flat" (the default), which is
always trained. Not called automatically by add() — training quality
depends on the training set being representative, and picking that set
on the caller's behalf is not this handle's decision to make.
Parameters:
-
vectors(list[list[float]]) –Training vectors, used to fit the index's internal quantizer/clustering. Should be representative of the data you'll actually add.
Raises:
-
DatasetError–If the underlying FAISS
train()call fails.
Source code in kedro_datasets_experimental/faiss/faiss_vector_store_dataset.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |