Class Introduction

Function

Configures data structure of the memory cache.

Prototype

from gptcache.config import Config
from mx_rag.cache import CacheConfig
# Inherited from Config
CacheConfig(cache_size, eviction_policy, auto_flush, data_save_folder, min_free_space, similarity_threshold, disable_report, lock)

Parameters

Parameter

Data Type

Required/Optional

Description

cache_size

Integer

Required

Cache size, indicating the number of cache entries.

The value cannot be less than or equal to 0.

The value range is (0, 100000].

eviction_policy

EvictPolicy

Optional

Cache aging policy.

The default value is LRU. For details, see EvictPolicy.

auto_flush

Integer

Optional

Data flushing frequency, that is, the number of cached data records to be flushed to drives.

The default value is 20.

The value range is (0, cache_size].

data_save_folder

String

Optional

Cache flushing path with up to 1024 characters. The path cannot be a soft link or a relative path.

  • The size of each file in the directory cannot exceed 100 GB, the level cannot exceed 64, and the total number of files cannot exceed 512.
  • The running user group and non-running users cannot have the write permission on the files in the directory.
  • All files within the directory, as well as the parent directory itself, must have their group ownership set to the running user.

The default value is user's home directory/Ascend/mxRag/cache_save_folder. If the directory does not exist, create it. The storage path cannot be in the path list: ["/etc", "/usr/bin", "/usr/lib", "/usr/lib64", "/sys/", "/dev/", "/sbin", "/tmp"].

min_free_space

Integer

Optional

Used to check the available space of the flushing path, in bytes. The default value is 1 GB.

The value range is [20 MB, 100 GB].

similarity_threshold

Float

Optional

Similarity calculation threshold.

The default value is 0.8.

The value range is [0.0, 1.0].

disable_report

Bool

Optional

Whether to support data maintenance and debugging.

The default value is False.

True indicates that the function is not supported, and False indicates that the function is supported.

lock

multiprocessing.synchronize.Lock, _thread.LockType

Optional

CacheConfig does not support multi-thread or multi-process processing. If you need to call this API in multi-thread or multi-process mode, you need to allocate a lock. The default value is None.

Value options:

None: No lock is used. In this case, this API does not support concurrency.

multiprocessing.Lock (): process lock. In this case, this API supports multi-process calling. threading.Lock (): thread lock. In this case, this API supports multi-thread calling.

  • This API uses the pickle module, which may be attacked by maliciously constructed data during unpickle. Ensure that data_save_folder is securely stored and only trusted data can be loaded.
  • For the memory cache, the size of the flushed file cannot exceed 100 MB.

Example

from paddle.base import libpaddle
from mx_rag.cache import CacheConfig
from mx_rag.cache import EvictPolicy
from mx_rag.cache import MxRAGCache
cache_config = CacheConfig(
    cache_size=100,
    eviction_policy=EvictPolicy.LRU,
    data_save_folder="path_to_cache_save_folder"
)
mxrag_l1_cache = MxRAGCache("memory_cache", cache_config)