|
| 1 | +--- |
| 2 | +title: "Ibm Db" |
| 3 | +id: integrations-ibm-db |
| 4 | +description: "Ibm Db integration for Haystack" |
| 5 | +slug: "/integrations-ibm-db" |
| 6 | +--- |
| 7 | + |
| 8 | + |
| 9 | +## haystack_integrations.components.retrievers.ibm_db.embedding_retriever |
| 10 | + |
| 11 | +### IBMDb2EmbeddingRetriever |
| 12 | + |
| 13 | +Retrieves documents from a IBMDb2DocumentStore using vector similarity. |
| 14 | + |
| 15 | +Use inside a Haystack pipeline after a text embedder: |
| 16 | + |
| 17 | +```python |
| 18 | +pipeline.add_component("embedder", SentenceTransformersTextEmbedder()) |
| 19 | +pipeline.add_component("retriever", IBMDb2EmbeddingRetriever( |
| 20 | + document_store=store, top_k=5 |
| 21 | +)) |
| 22 | +pipeline.connect("embedder.embedding", "retriever.query_embedding") |
| 23 | +``` |
| 24 | + |
| 25 | +#### __init__ |
| 26 | + |
| 27 | +```python |
| 28 | +__init__( |
| 29 | + *, |
| 30 | + document_store: IBMDb2DocumentStore, |
| 31 | + filters: dict[str, Any] | None = None, |
| 32 | + top_k: int = 10, |
| 33 | + filter_policy: FilterPolicy = FilterPolicy.REPLACE |
| 34 | +) -> None |
| 35 | +``` |
| 36 | + |
| 37 | +Initialize the IBMDb2EmbeddingRetriever. |
| 38 | + |
| 39 | +**Parameters:** |
| 40 | + |
| 41 | +- **document_store** (<code>IBMDb2DocumentStore</code>) – An instance of `IBMDb2DocumentStore`. |
| 42 | +- **filters** (<code>dict\[str, Any\] | None</code>) – Filters applied to the retrieved Documents. |
| 43 | +- **top_k** (<code>int</code>) – Maximum number of Documents to return. |
| 44 | +- **filter_policy** (<code>FilterPolicy</code>) – Policy to determine how filters are applied. |
| 45 | + |
| 46 | +**Raises:** |
| 47 | + |
| 48 | +- <code>TypeError</code> – If `document_store` is not an instance of `IBMDb2DocumentStore`. |
| 49 | + |
| 50 | +#### run |
| 51 | + |
| 52 | +```python |
| 53 | +run( |
| 54 | + query_embedding: list[float], |
| 55 | + filters: dict[str, Any] | None = None, |
| 56 | + top_k: int | None = None, |
| 57 | +) -> dict[str, list[Document]] |
| 58 | +``` |
| 59 | + |
| 60 | +Retrieve documents by vector similarity. |
| 61 | + |
| 62 | +**Parameters:** |
| 63 | + |
| 64 | +- **query_embedding** (<code>list\[float\]</code>) – Dense float vector from an embedder component. |
| 65 | +- **filters** (<code>dict\[str, Any\] | None</code>) – Runtime filters, merged with constructor filters according to filter_policy. |
| 66 | +- **top_k** (<code>int | None</code>) – Override the constructor top_k for this call. |
| 67 | + |
| 68 | +**Returns:** |
| 69 | + |
| 70 | +- <code>dict\[str, list\[Document\]\]</code> – A dictionary with key `documents` containing a list of matching :class:`Document` objects. |
| 71 | + |
| 72 | +#### to_dict |
| 73 | + |
| 74 | +```python |
| 75 | +to_dict() -> dict[str, Any] |
| 76 | +``` |
| 77 | + |
| 78 | +Serializes the component to a dictionary. |
| 79 | + |
| 80 | +**Returns:** |
| 81 | + |
| 82 | +- <code>dict\[str, Any\]</code> – Dictionary with serialized data. |
| 83 | + |
| 84 | +#### from_dict |
| 85 | + |
| 86 | +```python |
| 87 | +from_dict(data: dict[str, Any]) -> IBMDb2EmbeddingRetriever |
| 88 | +``` |
| 89 | + |
| 90 | +Deserializes the component from a dictionary. |
| 91 | + |
| 92 | +**Parameters:** |
| 93 | + |
| 94 | +- **data** (<code>dict\[str, Any\]</code>) – Dictionary to deserialize from. |
| 95 | + |
| 96 | +**Returns:** |
| 97 | + |
| 98 | +- <code>IBMDb2EmbeddingRetriever</code> – Deserialized component. |
| 99 | + |
| 100 | +## haystack_integrations.document_stores.ibm_db.document_store |
| 101 | + |
| 102 | +IBM DB2 Document Store for Haystack. |
| 103 | + |
| 104 | +### IBMDb2DocumentStore |
| 105 | + |
| 106 | +IBM DB2 Document Store for Haystack using vector search capabilities. |
| 107 | + |
| 108 | +This document store uses IBM DB2's native vector search functionality |
| 109 | +to store and retrieve documents with embeddings. |
| 110 | + |
| 111 | +#### __init__ |
| 112 | + |
| 113 | +```python |
| 114 | +__init__( |
| 115 | + *, |
| 116 | + database: str, |
| 117 | + hostname: str, |
| 118 | + username: Secret = Secret.from_env_var("DB2_USERNAME"), |
| 119 | + password: Secret = Secret.from_env_var("DB2_PASSWORD"), |
| 120 | + port: int = 50000, |
| 121 | + protocol: str = "TCPIP", |
| 122 | + schema: str | None = None, |
| 123 | + use_ssl: bool = False, |
| 124 | + ssl_certificate: str | None = None, |
| 125 | + connection_options: dict[str, Any] | None = None, |
| 126 | + table_name: str = "haystack_documents", |
| 127 | + embedding_dim: int = 768, |
| 128 | + distance_metric: Literal["EUCLIDEAN", "COSINE", "MANHATTAN"] = "COSINE", |
| 129 | + recreate_table: bool = False |
| 130 | +) |
| 131 | +``` |
| 132 | + |
| 133 | +Initialize the IBM DB2 Document Store. |
| 134 | + |
| 135 | +**Parameters:** |
| 136 | + |
| 137 | +- **database** (<code>str</code>) – Database name |
| 138 | +- **hostname** (<code>str</code>) – Database server hostname |
| 139 | +- **username** (<code>Secret</code>) – Database username as a `Secret`, e.g. `Secret.from_env_var("DB2_USERNAME")`. |
| 140 | +- **password** (<code>Secret</code>) – Database password as a `Secret`, e.g. `Secret.from_env_var("DB2_PASSWORD")`. |
| 141 | +- **port** (<code>int</code>) – Database server port (default: 50000) |
| 142 | +- **protocol** (<code>str</code>) – Connection protocol (default: "TCPIP") |
| 143 | +- **schema** (<code>str | None</code>) – Database schema (optional) |
| 144 | +- **use_ssl** (<code>bool</code>) – Enable SSL/TLS connection (default: False) |
| 145 | +- **ssl_certificate** (<code>str | None</code>) – Path to SSL certificate file (optional, required if use_ssl is True) |
| 146 | +- **connection_options** (<code>dict\[str, Any\] | None</code>) – Additional connection options as dict (optional) |
| 147 | +- **table_name** (<code>str</code>) – Name of the table to store documents (default: "haystack_documents") |
| 148 | +- **embedding_dim** (<code>int</code>) – Dimension of embedding vectors (default: 768) |
| 149 | +- **distance_metric** (<code>Literal['EUCLIDEAN', 'COSINE', 'MANHATTAN']</code>) – Distance metric for similarity search (default: "COSINE") |
| 150 | +- **recreate_table** (<code>bool</code>) – If True, drop and recreate the table (default: False) |
| 151 | + |
| 152 | +#### count_documents |
| 153 | + |
| 154 | +```python |
| 155 | +count_documents() -> int |
| 156 | +``` |
| 157 | + |
| 158 | +Count all documents in the store. |
| 159 | + |
| 160 | +**Returns:** |
| 161 | + |
| 162 | +- <code>int</code> – Number of documents |
| 163 | + |
| 164 | +#### count_documents_by_filter |
| 165 | + |
| 166 | +```python |
| 167 | +count_documents_by_filter(filters: dict[str, Any] | None = None) -> int |
| 168 | +``` |
| 169 | + |
| 170 | +Count documents that match the provided filters. |
| 171 | + |
| 172 | +**Parameters:** |
| 173 | + |
| 174 | +- **filters** (<code>dict\[str, Any\] | None</code>) – Filters to apply. See Haystack documentation for filter syntax. |
| 175 | + |
| 176 | +**Returns:** |
| 177 | + |
| 178 | +- <code>int</code> – Number of documents matching the filters |
| 179 | + |
| 180 | +#### write_documents |
| 181 | + |
| 182 | +```python |
| 183 | +write_documents( |
| 184 | + documents: list[Document], policy: DuplicatePolicy = DuplicatePolicy.NONE |
| 185 | +) -> int |
| 186 | +``` |
| 187 | + |
| 188 | +Write documents to the store. |
| 189 | + |
| 190 | +**Parameters:** |
| 191 | + |
| 192 | +- **documents** (<code>list\[Document\]</code>) – List of documents to write |
| 193 | +- **policy** (<code>DuplicatePolicy</code>) – Policy for handling duplicate documents |
| 194 | + |
| 195 | +**Returns:** |
| 196 | + |
| 197 | +- <code>int</code> – Number of documents written |
| 198 | + |
| 199 | +**Raises:** |
| 200 | + |
| 201 | +- <code>ValueError</code> – If documents is not a list of Document objects or has invalid embeddings |
| 202 | +- <code>TypeError</code> – If embeddings have invalid types |
| 203 | +- <code>DuplicateDocumentError</code> – If a document with the same id already exists and policy is FAIL or NONE |
| 204 | + |
| 205 | +#### filter_documents |
| 206 | + |
| 207 | +```python |
| 208 | +filter_documents(filters: dict[str, Any] | None = None) -> list[Document] |
| 209 | +``` |
| 210 | + |
| 211 | +Filter documents using SQL-based metadata and field conditions. |
| 212 | + |
| 213 | +**Parameters:** |
| 214 | + |
| 215 | +- **filters** (<code>dict\[str, Any\] | None</code>) – Optional filter dictionary to constrain the returned documents. |
| 216 | + |
| 217 | +**Returns:** |
| 218 | + |
| 219 | +- <code>list\[Document\]</code> – List of matching documents. |
| 220 | + |
| 221 | +#### delete_documents |
| 222 | + |
| 223 | +```python |
| 224 | +delete_documents(document_ids: list[str]) -> None |
| 225 | +``` |
| 226 | + |
| 227 | +Delete documents by their IDs. |
| 228 | + |
| 229 | +**Parameters:** |
| 230 | + |
| 231 | +- **document_ids** (<code>list\[str\]</code>) – List of document IDs to delete |
| 232 | + |
| 233 | +#### delete_by_filter |
| 234 | + |
| 235 | +```python |
| 236 | +delete_by_filter(filters: dict[str, Any] | None = None) -> int |
| 237 | +``` |
| 238 | + |
| 239 | +Delete documents that match the provided filters. |
| 240 | + |
| 241 | +**Parameters:** |
| 242 | + |
| 243 | +- **filters** (<code>dict\[str, Any\] | None</code>) – Filters to apply. See Haystack documentation for filter syntax. |
| 244 | + |
| 245 | +**Returns:** |
| 246 | + |
| 247 | +- <code>int</code> – Number of documents deleted |
| 248 | + |
| 249 | +#### delete_all_documents |
| 250 | + |
| 251 | +```python |
| 252 | +delete_all_documents(recreate_index: bool = False) -> int |
| 253 | +``` |
| 254 | + |
| 255 | +Delete all documents from the document store. |
| 256 | + |
| 257 | +**Parameters:** |
| 258 | + |
| 259 | +- **recreate_index** (<code>bool</code>) – If True, recreate the table after deletion |
| 260 | + |
| 261 | +**Returns:** |
| 262 | + |
| 263 | +- <code>int</code> – Number of documents deleted |
| 264 | + |
| 265 | +#### update_by_filter |
| 266 | + |
| 267 | +```python |
| 268 | +update_by_filter( |
| 269 | + filters: dict[str, Any] | None = None, meta: dict[str, Any] | None = None |
| 270 | +) -> int |
| 271 | +``` |
| 272 | + |
| 273 | +Update documents that match the provided filters. |
| 274 | + |
| 275 | +**Parameters:** |
| 276 | + |
| 277 | +- **filters** (<code>dict\[str, Any\] | None</code>) – Filters to apply. See Haystack documentation for filter syntax. |
| 278 | +- **meta** (<code>dict\[str, Any\] | None</code>) – Dictionary of metadata fields to update |
| 279 | + |
| 280 | +**Returns:** |
| 281 | + |
| 282 | +- <code>int</code> – Number of documents updated |
| 283 | + |
| 284 | +#### get_metadata_field_unique_values |
| 285 | + |
| 286 | +```python |
| 287 | +get_metadata_field_unique_values(field: str) -> list[Any] |
| 288 | +``` |
| 289 | + |
| 290 | +Get all unique values for a given metadata field. |
| 291 | + |
| 292 | +**Parameters:** |
| 293 | + |
| 294 | +- **field** (<code>str</code>) – The metadata field name (can include 'meta.' prefix) |
| 295 | + |
| 296 | +**Returns:** |
| 297 | + |
| 298 | +- <code>list\[Any\]</code> – List of unique values for the field |
| 299 | + |
| 300 | +#### get_metadata_field_min_max |
| 301 | + |
| 302 | +```python |
| 303 | +get_metadata_field_min_max(field: str) -> dict[str, Any] |
| 304 | +``` |
| 305 | + |
| 306 | +Get the minimum and maximum values for a numeric metadata field. |
| 307 | + |
| 308 | +**Parameters:** |
| 309 | + |
| 310 | +- **field** (<code>str</code>) – The metadata field name (can include 'meta.' prefix) |
| 311 | + |
| 312 | +**Returns:** |
| 313 | + |
| 314 | +- <code>dict\[str, Any\]</code> – Dictionary with 'min' and 'max' keys |
| 315 | + |
| 316 | +#### get_metadata_fields_info |
| 317 | + |
| 318 | +```python |
| 319 | +get_metadata_fields_info() -> dict[str, dict[str, Any]] |
| 320 | +``` |
| 321 | + |
| 322 | +Get information about all metadata fields including their types. |
| 323 | + |
| 324 | +**Returns:** |
| 325 | + |
| 326 | +- <code>dict\[str, dict\[str, Any\]\]</code> – Dictionary mapping field names to their type information |
| 327 | + |
| 328 | +#### count_unique_metadata_by_filter |
| 329 | + |
| 330 | +```python |
| 331 | +count_unique_metadata_by_filter( |
| 332 | + filters: dict[str, Any] | None = None, |
| 333 | + metadata_fields: list[str] | None = None, |
| 334 | +) -> dict[str, int] |
| 335 | +``` |
| 336 | + |
| 337 | +Count unique values for specified metadata fields, optionally filtered. |
| 338 | + |
| 339 | +**Parameters:** |
| 340 | + |
| 341 | +- **filters** (<code>dict\[str, Any\] | None</code>) – Optional filters to apply before counting |
| 342 | +- **metadata_fields** (<code>list\[str\] | None</code>) – List of metadata field names to count unique values for |
| 343 | + |
| 344 | +**Returns:** |
| 345 | + |
| 346 | +- <code>dict\[str, int\]</code> – Dictionary mapping field names to their unique value counts |
| 347 | + |
| 348 | +#### to_dict |
| 349 | + |
| 350 | +```python |
| 351 | +to_dict() -> dict[str, Any] |
| 352 | +``` |
| 353 | + |
| 354 | +Serialize the document store to a dictionary. |
| 355 | + |
| 356 | +**Returns:** |
| 357 | + |
| 358 | +- <code>dict\[str, Any\]</code> – Dictionary representation |
| 359 | + |
| 360 | +#### from_dict |
| 361 | + |
| 362 | +```python |
| 363 | +from_dict(data: dict[str, Any]) -> IBMDb2DocumentStore |
| 364 | +``` |
| 365 | + |
| 366 | +Deserialize the document store from a dictionary. |
| 367 | + |
| 368 | +**Parameters:** |
| 369 | + |
| 370 | +- **data** (<code>dict\[str, Any\]</code>) – Dictionary representation |
| 371 | + |
| 372 | +**Returns:** |
| 373 | + |
| 374 | +- <code>IBMDb2DocumentStore</code> – IBMDb2DocumentStore instance |
0 commit comments