> For the complete documentation index, see [llms.txt](https://nomadamas.gitbook.io/ragchain-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nomadamas.gitbook.io/ragchain-docs/utils/file-cache.md).

# File Cache

The purpose of `FileCache` is to remove duplicate documents since users are likely to load duplicate document files if they ingest files multiple times.

The `FileCache` is a util that checks the DB for duplicate file check files.

## Usage

At first, import FileCache.

```python
from RAGchain.utils.file_cache import FileCache
from RAGchain.DB import PickleDB
from langchain.schema import Document
```

We will intentionally generate db saved duplicate files to illustrate.

```python
test_passages: List[Passage] = [
    Passage(content="test1", filepath="test1"),
    Passage(content="test2", filepath="test2"),
    Passage(content="test3", filepath="test2")
]

test_documents: List[Document] = [
    Document(page_content="ttt1211", metadata={"source": "test1"}),
    Document(page_content="asdf", metadata={"source": "test2"}),
    Document(page_content="hgh", metadata={"source": "test3"}),
    Document(page_content="egrgfg", metadata={"source": "test4"}),
    Document(page_content="hhhh", metadata={"source": "test4"}),
]
```

Create an instance and input parameter. At this example, we use [`PickleDB`](/ragchain-docs/ragchain-structure/db/pickle-db.md).

<pre class="language-python"><code class="lang-python">db = PickleDB(save_path = "your-pickle-path.pkl"))
<strong>db.creat_or_load()
</strong><strong>db.save(test_passages)
</strong><strong>file_cache = FileCache(db)
</strong></code></pre>

And then, use `delete_duplicate()` to detect what file is already saved in DB. You can get List\[Document] with duplicate document removed!

```python
test_documents = file_cache.delete_duplicate(test_documents)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://nomadamas.gitbook.io/ragchain-docs/utils/file-cache.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
