pangukitsappdev.api.memory.cache package¶
Submodules¶
pangukitsappdev.api.memory.cache.base module¶
- class pangukitsappdev.api.memory.cache.base.CacheApi¶
基类:
ABC
SDK封装的缓存对外接口
- abstract clear() None ¶
清空 Args:
- Returns:
LLMResp
pangukitsappdev.api.memory.cache.cache_config module¶
- class pangukitsappdev.api.memory.cache.cache_config.CacheStoreConfig(_env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]] = '<object object>', _env_file_encoding: Optional[str] = None, _env_nested_delimiter: Optional[str] = None, _secrets_dir: Optional[Union[str, PathLike]] = None, *, store_name: Optional[str] = None, server_info: ServerInfo = None, embedding: Optional[EmbeddingApi] = None, vector_store_name: str = 'css', distance_strategy: str = 'inner_product', score_threshold: float = 0.2, session_tag: str = '', expire_after_access: int = -1, expire_after_write: int = -1, maximum_size: int = -1)¶
-
缓存存储的相关配置 Attributes:
store_name: 存储名称 server_info: ServerInfo,存储服务器连接相关信息,默认使用redis的连接 embedding: embedding接口,语义缓存时需要使用 vector_store_name: 向量语义缓存时,设置库名,默认使用css存储 distance_strategy: 检索模式,默认使用内积inner_product score_threshold: 语义缓存, 相似度评分阈值;评分低于阈值表示不相似 session_tag: 用户指定cache会话标志 expire_after_access: 访问后到期时间,单位为秒, 默认不设置过期 expire_after_write: 写入后到期时间,单位为秒, 默认不设置过期 maximum_size: 基于个数大小
- distance_strategy: str¶
- embedding: Optional[EmbeddingApi]¶
- expire_after_access: int¶
- expire_after_write: int¶
- maximum_size: int¶
- score_threshold: float¶
- server_info: ServerInfo¶
- session_tag: str¶
- store_name: Optional[str]¶
- vector_store_name: str¶
- class pangukitsappdev.api.memory.cache.cache_config.ServerInfoRedis(_env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]] = '<object object>', _env_file_encoding: Optional[str] = None, _env_nested_delimiter: Optional[str] = None, _secrets_dir: Optional[Union[str, PathLike]] = None, *, url: Optional[str] = None, user: Optional[str] = None, password: Optional[str] = None)¶
基类:
ServerInfo
- get_urls() [<class 'str'>] ¶
- has_auth() bool ¶
- password: Optional[str]¶
- url: Optional[str]¶
- user: Optional[str]¶
- class pangukitsappdev.api.memory.cache.cache_config.ServerInfoSql(_env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]] = '<object object>', _env_file_encoding: Optional[str] = None, _env_nested_delimiter: Optional[str] = None, _secrets_dir: Optional[Union[str, PathLike]] = None, *, url: Optional[str] = None, user: Optional[str] = None, password: Optional[str] = None, pool_size: Optional[str] = 5)¶
基类:
ServerInfo
sql数据存储相关的配置 Attributes:
url: 拼接好的url; 如jdbc场景 pool_size: 连接池大小
- get_urls() [<class 'str'>] ¶
- pool_size: Optional[str]¶
pangukitsappdev.api.memory.cache.factory module¶
- class pangukitsappdev.api.memory.cache.factory.Caches¶
基类:
object
- caches_map: Dict[str, Type[CacheApi]] = {'inMemory': <class 'pangukitsappdev.cache.in_memory.InMemoryCacheApi'>, 'redis': <class 'pangukitsappdev.cache.ttl_redis.RedisCacheApi'>, 'semantic_gptcache': <class 'pangukitsappdev.cache.gptcache_adapter.SemanticGptCacheApi'>, 'semantic_redis': <class 'pangukitsappdev.cache.ttl_redis.RedisSemanticCacheApi'>, 'sql': <class 'pangukitsappdev.cache.sql.SqlCacheApi'>}¶
- classmethod of(cache_name: str, cache_config: Optional[CacheStoreConfig] = None) CacheApi ¶
根据名字创建一个CacheApi的实现类 cache_name和cache_config.store_name不可同时为空 Args:
cache_name: (Optional)cache的名字,唯一标识一个CacheApi的实现类 cache_config: (Optional)CacheApi的相关配置,如果不传递则从默认配置文件中或者环境变量中获取
- Returns:
一个CacheApi的实现类