Skip to contents

Knowledge Store

Knowledge Store

Value

An R6 object of class knowledge_store.

Details

Persistent JSONL key-value knowledge base. Each entry stores a key, value, optional metadata, and timestamp.

Methods


Method new()

Create a new knowledge store.

Usage

knowledge_store$new(path = NULL, encryption_key = NULL, audit_log = NULL)

Arguments

path

Optional file path for JSONL persistence. NULL for in-memory only.

encryption_key

Raw 32-byte key for AES-256-CBC encryption at rest, or NULL to check the SECURECONTEXT_ENCRYPTION_KEY env var. If neither is set, data is stored unencrypted.

audit_log

Optional path to a JSONL audit log file. If non-NULL, store operations are logged via log_store_event().


Method set()

Set a key-value pair (upsert).

Usage

knowledge_store$set(key, value, metadata = list())

Arguments

key

Character key.

value

Any R object that can be serialized to JSON.

metadata

Named list of metadata.


Method get()

Get a value by key.

Usage

knowledge_store$get(key, default = NULL)

Arguments

key

Character key.

default

Value to return if key not found.

Returns

The stored value, or default.


Method delete()

Delete a key.

Usage

knowledge_store$delete(key)

Arguments

key

Character key.


Method search()

Search keys by regex pattern.

Usage

knowledge_store$search(pattern)

Arguments

pattern

Regular expression.

Returns

Character vector of matching keys.


Method list()

List all keys.

Usage

knowledge_store$list(n = NULL)

Arguments

n

Optional maximum number to return.

Returns

Character vector of keys.


Method size()

Number of entries.

Usage

knowledge_store$size()

Returns

Integer.


Method save()

Save to JSONL file.

Usage

knowledge_store$save()


Method load()

Load from JSONL file.

Usage

knowledge_store$load()


Method clone()

The objects of this class are cloneable with this method.

Usage

knowledge_store$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

ks <- knowledge_store$new()
ks$set("color", "blue", metadata = list(source = "test"))
ks$get("color")
#> [1] "blue"
ks$search("col")
#> [1] "color"
ks$size()
#> [1] 1