org.llm4s.agent.memory.testkit

Members list

Type members

Classlikes

@Experimental
trait MemoryContractCases extends AnyFlatSpecLike, Matchers, EitherValues, OptionValues

How MemoryStoreContract and TransactionalMemoryStoreContract register their cases, and the two ways a store's spec says that a case does not hold for it yet:

How MemoryStoreContract and TransactionalMemoryStoreContract register their cases, and the two ways a store's spec says that a case does not hold for it yet:

  • knownFailures: a case the store fails today because of a known defect, named with the issue that tracks it. The case still runs, as ScalaTest's pendingUntilFixed: it is reported pending while it fails and fails once it passes, so the change that fixes the defect also removes the entry.
  • unsupported: a case the store cannot run at all, with the reason. It is cancelled.

A name in either map that matches no case fails the suite, so a renamed case cannot silently stop being excused. The name of a case is the text after should, as the suite's output shows it.

Attributes

Companion
object
Source
MemoryContractCases.scala
Supertypes
trait OptionValues
trait EitherValues
trait Matchers
trait Explicitly
trait MatcherWords
trait Tolerance
trait AnyFlatSpecLike
trait Documenting
trait Alerting
trait Notifying
trait Informing
trait CanVerb
trait MustVerb
trait ShouldVerb
trait TestRegistration
trait TestSuite
trait Suite
trait Serializable
trait Assertions
trait TripleEquals
trait TripleEqualsSupport
class Object
trait Matchable
class Any
Show all
Known subtypes
@Experimental

Helpers for the specs that run the contracts.

Helpers for the specs that run the contracts.

Attributes

Companion
trait
Source
MemoryContractCases.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Experimental

The memories and filters every store answers alike (#3031, #3329): what MemoryFilter.matches says about each of fixtures is what a store must answer for recall, count, deleteMatching and search with each of filters. MemoryStoreContract runs the whole matrix, and random trees of its leaves (randomTree).

The memories and filters every store answers alike (#3031, #3329): what MemoryFilter.matches says about each of fixtures is what a store must answer for recall, count, deleteMatching and search with each of filters. MemoryStoreContract runs the whole matrix, and random trees of its leaves (randomTree).

The rows are chosen to catch a store that translates a filter loosely: % and _ read as LIKE wildcards, case folding that is not String.toLowerCase's, a NULL column that makes Not drop a row, a metadata key read as a JSON path.

Attributes

Source
MemoryFilterMatrix.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Experimental

The contract every org.llm4s.agent.memory.MemoryStore must meet (#3038, #3329), as a ScalaTest suite: mix it into a spec, implement storeName, semantic and withStore, and every case below runs against your store:

The contract every org.llm4s.agent.memory.MemoryStore must meet (#3038, #3329), as a ScalaTest suite: mix it into a spec, implement storeName, semantic and withStore, and every case below runs against your store:

class MyMemoryStoreContractSpec extends MemoryStoreContract {
 protected def storeName: String = "MyMemoryStore"
 protected def semantic: Boolean = false
 protected def withStore[A](embeddings: EmbeddingService)(body: MemoryStore => A): A = {
   val store = MyMemoryStore.open().fold(e => fail(e.message), identity)
   MemoryContractCases.after(store.close())(body(store))
 }
}

The cases:

  • '''Writes.''' A write over an existing id replaces every field; a batch keeps a repeated id's last occurrence; update changes every field, refuses a changed id, answers a missing one with NotFoundError, and drops an embedding computed for the old content; replace stores, then deletes; delete, clear and stats.
  • '''Filters.''' Every filter of MemoryFilterMatrix, and 300 random trees of its leaves, in recall, count, search and deleteMatching; a limit applied after the filter; sub-millisecond time bounds; metadata keys matched exactly.
  • '''The keyset cursor.''' Recall order (newest first, then id by its UTF-8 bytes, descending), and MemoryFilter.Preceding paging past memories that share a time, as consolidation pages (LLMMemoryManager.consolidatePage): every memory once, a replacement between pages neither repeating nor skipping one.
  • '''Durability.''' durable answers expectDurable; a durable store gives back everything it held when its storage is opened again (withReopened).
  • '''Limits and blank queries''', and, for a store that searches by embedding, the shared score rule (org.llm4s.vectorstore.SearchScores, #3037): (1 + cos) / 2, a vector that cannot be compared left out, a store of another dimension a ConfigurationError, nothing stored when embedding fails.

Eviction under bounds, applied writes and fencing are TransactionalMemoryStoreContract's. A store with a known defect lists the case in knownFailures with its issue; one that cannot run a case lists it in unsupported (see MemoryContractCases). Timestamps are whole milliseconds, the precision every store keeps.

Attributes

Companion
object
Source
MemoryStoreContract.scala
Supertypes
trait OptionValues
trait EitherValues
trait Matchers
trait Explicitly
trait MatcherWords
trait Tolerance
trait AnyFlatSpecLike
trait Documenting
trait Alerting
trait Notifying
trait Informing
trait CanVerb
trait MustVerb
trait ShouldVerb
trait TestRegistration
trait TestSuite
trait Suite
trait Serializable
trait Assertions
trait TripleEquals
trait TripleEqualsSupport
class Object
trait Matchable
class Any
Show all
@Experimental

Attributes

Companion
trait
Source
MemoryStoreContract.scala
Supertypes
class Object
trait Matchable
class Any
Self type

The contract every org.llm4s.agent.memory.TransactionalMemoryStore must meet (design §4.31, #3328, #3329), as a ScalaTest suite: applied writes recorded with the write, fenced by the token per scope, and bounded by eviction in the same transaction. Mix it into a spec and implement storeName and newStore (or withStore, to release the store afterwards).

The contract every org.llm4s.agent.memory.TransactionalMemoryStore must meet (design §4.31, #3328, #3329), as a ScalaTest suite: applied writes recorded with the write, fenced by the token per scope, and bounded by eviction in the same transaction. Mix it into a spec and implement storeName and newStore (or withStore, to release the store afterwards).

The cases:

  • '''Applied writes.''' A write and its recorded outcome; a key applied again replays the outcome and writes nothing, even after what it stored was deleted; a replacement whose sources another writer already replaced writes nothing; forgetApplied; applied keys kept by clear().
  • '''Fencing.''' A token older than its scope's newest refused by every operation, changing nothing.
  • '''Eviction.''' Beyond maxMemories and maxBytes, lowest importance first (none counts as 0.5), then oldest, then by id (its UTF-8 bytes, as recall orders ids); with an owner, only the owner's memories counted and evicted.
  • '''Eviction against concurrent writers''' (#3328), on two handles of one storage (withSecondHandle): a memory another handle makes important while a write evicts is either evicted before that write lands - and then the other handle's update fails - or kept; never evicted after it.

A store with a known defect lists the case in knownFailures with its issue; one that cannot run a case lists it in unsupported (see MemoryContractCases).

Attributes

Source
TransactionalMemoryStoreContract.scala
Supertypes
trait OptionValues
trait EitherValues
trait Matchers
trait Explicitly
trait MatcherWords
trait Tolerance
trait AnyFlatSpecLike
trait Documenting
trait Alerting
trait Notifying
trait Informing
trait CanVerb
trait MustVerb
trait ShouldVerb
trait TestRegistration
trait TestSuite
trait Suite
trait Serializable
trait Assertions
trait TripleEquals
trait TripleEqualsSupport
class Object
trait Matchable
class Any
Show all