IRISDocumentStore¶
IRISDocumentStore ¶
IRISDocumentStore(*, connection_string: Secret | None = None, username: Secret | None = None, password: Secret | None = None, table_name: str = 'HaystackDocuments', embedding_dim: int = 384, bm25_k1: float = 1.5, bm25_b: float = 0.75, recreate_table: bool = False)
A DocumentStore backed by InterSystems IRIS_.
Uses IRIS native VECTOR(DOUBLE, N) column for embedding storage and VECTOR_COSINE function for semantic similarity search.
.. _InterSystems IRIS: https://www.intersystems.com/products/intersystems-iris/
Credentials
Pass the connection string and password as Haystack :class:~haystack.utils.Secret objects. The recommended approach is to export environment variables and use :meth:~haystack.utils.Secret.from_env_var:
.. code-block:: bash
export IRIS_CONNECTION_STRING="localhost:1972/USER"
export IRIS_USERNAME="_system"
export IRIS_PASSWORD="SYS"
.. code-block:: python
from intersystems_iris_haystack.document_stores import IRISDocumentStore
store = IRISDocumentStore()
Retrievers
Use the companion retrievers for embedding-based and keyword-based search:
.. code-block:: python
from intersystems_iris_haystack.components.retrievers import (
IRISEmbeddingRetriever,
IRISBm25Retriever,
)
Table schema (created automatically if it doesn't exist)
.. code-block:: sql
CREATE TABLE SQLUser.<table_name> (
id VARCHAR(128) NOT NULL PRIMARY KEY,
content LONGVARCHAR,
meta LONGVARCHAR, -- JSON with sort_keys=True
score DOUBLE,
embedding VECTOR(DOUBLE, <embedding_dim>)
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_string | Secret | None | IRIS DB-API connection string in the format | None |
username | Secret | None | IRIS username. Resolved from | None |
password | Secret | None | IRIS password. Resolved from | None |
table_name | str | Name of the SQL table (without schema). The | 'HaystackDocuments' |
embedding_dim | int | Number of dimensions of the embedding vectors. Must match the embedding model used at indexing time. | 384 |
bm25_k1 | float | BM25 term-frequency saturation parameter (typical: 1.2-2.0). | 1.5 |
bm25_b | float | BM25 length-normalization parameter (0.0-1.0). | 0.75 |
recreate_table | bool | Drop and re-create the table on initialization. Use with caution — all data will be lost. | False |
Raises:
| Type | Description |
|---|---|
ConnectionError | If unable to connect to IRIS after :data: |
Source code in src/intersystems_iris_haystack/document_stores/document_store.py
count_documents ¶
Return the number of documents in the store.
Returns:
| Type | Description |
|---|---|
int | Total document count. |
Example
store.count_documents() 5
Source code in src/intersystems_iris_haystack/document_stores/document_store.py
filter_documents ¶
Return documents matching the provided filters.
Filtering is performed in-memory after loading all documents from IRIS. This ensures compatibility with IRIS Community Edition (which lacks JSON_VALUE as a native SQL function) and supports all Python types and operators defined by the Haystack protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters | dict[str, Any] | None | Filter in legacy format | None |
Returns:
| Type | Description |
|---|---|
list[Document] | Documents satisfying the filter. |
Examples:
No filter — all documents::
store.filter_documents()
Legacy filter::
store.filter_documents({"category": "db"})
Integer filter::
store.filter_documents({"year": 2024})
Official Haystack filter with AND and >=::
store.filter_documents({
"operator": "AND",
"conditions": [
{"field": "meta.category", "operator": "==", "value": "db"},
{"field": "meta.year", "operator": ">=", "value": 2023},
],
})
Source code in src/intersystems_iris_haystack/document_stores/document_store.py
write_documents ¶
Persist documents to IRIS.
Documents with embeddings are stored using TO_VECTOR(?, DOUBLE) for native IRIS vector type conversion. The meta field is serialized with json.dumps(sort_keys=True) to guarantee deterministic key ordering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents | list[Document] | List of :class: | required |
policy | DuplicatePolicy | Duplicate handling policy:
| NONE |
Returns:
| Type | Description |
|---|---|
int | Number of documents written. |
Raises:
| Type | Description |
|---|---|
DuplicateDocumentError | If |
ValueError | If |
Example
from haystack import Document from haystack.document_stores.types import DuplicatePolicy store.write_documents( ... [Document(content="Hello IRIS!", meta={"lang": "en"})], ... policy=DuplicatePolicy.OVERWRITE, ... ) 1
Source code in src/intersystems_iris_haystack/document_stores/document_store.py
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 441 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
delete_documents ¶
Delete documents by ID.
Accepts an empty list without error (idempotent). Non-existent IDs are silently ignored by IRIS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document_ids | list[str] | List of document IDs to remove. | required |
Example
store.delete_documents(["id-1", "id-2"])
Source code in src/intersystems_iris_haystack/document_stores/document_store.py
to_dict ¶
Serialize the store for use in Haystack YAML/JSON pipelines.
The password Secret is serialized according to the Haystack secret protocol — the resolved value is never included.
Returns:
| Type | Description |
|---|---|
dict | Serializable dictionary. |
Example
d = store.to_dict() d["type"] 'intersystems_iris_haystack.document_stores.document_store.IRISDocumentStore'
Source code in src/intersystems_iris_haystack/document_stores/document_store.py
from_dict classmethod ¶
Deserialize the store from a dictionary.
Called automatically by Haystack when loading a pipeline from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | dict[str, Any] | Dictionary in the format produced by :meth: | required |
Returns:
| Type | Description |
|---|---|
IRISDocumentStore | |
Source code in src/intersystems_iris_haystack/document_stores/document_store.py
close ¶
Close the IRIS connection (idempotent).