Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.0-rc0
3.3.0-rc0
4 changes: 2 additions & 2 deletions docs-website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
beforeDefaultRemarkPlugins: [require('./src/remark/versionedReferenceLinks')],
versions: {
current: {
label: '3.2-unstable',
label: '3.3-unstable',
path: 'next',
banner: 'unreleased',
},
Expand Down Expand Up @@ -134,7 +134,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
exclude: ['**/_templates/**'],
versions: {
current: {
label: '3.2-unstable',
label: '3.3-unstable',
path: 'next',
banner: 'unreleased',
},
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
title: "Caching"
id: caching-api
description: "Checks if any document coming from the given URL is already present in the store."
slug: "/caching-api"
---


## cache_checker

### CacheChecker

Checks for the presence of documents in a Document Store based on a specified field in each document's metadata.

If matching documents are found, they are returned as "hits". If not found in the cache, the items
are returned as "misses".

### Usage example

```python
from haystack import Document
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.caching.cache_checker import CacheChecker

docstore = InMemoryDocumentStore()
documents = [
Document(content="doc1", meta={"url": "https://example.com/1"}),
Document(content="doc2", meta={"url": "https://example.com/2"}),
Document(content="doc3", meta={"url": "https://example.com/1"}),
Document(content="doc4", meta={"url": "https://example.com/2"}),
]
docstore.write_documents(documents)
checker = CacheChecker(docstore, cache_field="url")
results = checker.run(items=["https://example.com/1", "https://example.com/5"])
assert results == {"hits": [documents[0], documents[2]], "misses": ["https://example.com/5"]}
```

#### __init__

```python
__init__(document_store: DocumentStore, cache_field: str) -> None
```

Creates a CacheChecker component.

**Parameters:**

- **document_store** (<code>DocumentStore</code>) – Document Store to check for the presence of specific documents.
- **cache_field** (<code>str</code>) – Name of the document's metadata field
to check for cache hits.

#### to_dict

```python
to_dict() -> dict[str, Any]
```

Serializes the component to a dictionary.

**Returns:**

- <code>dict\[str, Any\]</code> – Dictionary with serialized data.

#### from_dict

```python
from_dict(data: dict[str, Any]) -> CacheChecker
```

Deserializes the component from a dictionary.

**Parameters:**

- **data** (<code>dict\[str, Any\]</code>) – Dictionary to deserialize from.

**Returns:**

- <code>CacheChecker</code> – Deserialized component.

#### run

```python
run(items: list[Any]) -> dict[str, Any]
```

Checks if any document associated with the specified cache field is already present in the store.

**Parameters:**

- **items** (<code>list\[Any\]</code>) – Values to be checked against the cache field.

**Returns:**

- <code>dict\[str, Any\]</code> – A dictionary with two keys:
- `hits` - Documents that matched with at least one of the items.
- `misses` - Items that were not present in any documents.

#### run_async

```python
run_async(items: list[Any]) -> dict[str, Any]
```

Asynchronously checks if any document associated with the specified cache field is already present in the store.

**Parameters:**

- **items** (<code>list\[Any\]</code>) – Values to be checked against the cache field.

**Returns:**

- <code>dict\[str, Any\]</code> – A dictionary with two keys:
- `hits` - Documents that matched with at least one of the items.
- `misses` - Items that were not present in any documents.

#### close

```python
close() -> None
```

Release the synchronous resources of the underlying Document Store.

#### close_async

```python
close_async() -> None
```

Release the asynchronous resources of the underlying Document Store.
Loading