class

Memvid::Memory

Inherits Reference < Object

A single-file AI memory store.

Memory provides a high-level interface for storing and searching content in a memvid .mv2 file.

Constructors

create(path : String) : Memory

Creates a new memory file at the specified path.

Raises Error if the file cannot be created.

Source
open(path : String) : Memory

Opens an existing memory file.

Raises Error if the file cannot be opened.

Source

Class methods

create(path : String, & : Memory -> ) : Nil

Creates a new memory file and yields it to the block. The memory is automatically closed when the block returns.

Source
open(path : String, & : Memory -> ) : Nil

Opens an existing memory file and yields it to the block. The memory is automatically closed when the block returns.

Source

Instance methods

ask(question : String, top_k : Int32 = 10) : AskResponse

Ask a question using RAG (Retrieval-Augmented Generation).

This is a convenience method that creates an AskRequest with defaults. Returns retrieved context; answer synthesis requires an external LLM.

Source
ask(request : AskRequest) : AskResponse

Ask a question with full request parameters.

Source
close

Closes the memory handle.

After calling this method, the Memory instance is no longer usable. This is called automatically when using the block forms of create or open.

Source
closed?

Returns true if the memory has been closed.

Source
commit

Commits pending changes to disk.

This should be called after adding content to ensure it is persisted.

Source
delete_frame(id : UInt64) : UInt64

Soft-deletes a frame.

The frame data is not immediately removed; a tombstone entry is created. Returns the WAL sequence number.

Raises FrameNotFoundError if the frame does not exist.

Source
finalize

Finalizer to ensure the handle is closed.

Source
frame(id : UInt64) : Frame

Gets frame metadata by ID.

Raises FrameNotFoundError if the frame does not exist.

Source
frame_by_uri(uri : String) : Frame

Gets frame metadata by URI.

Raises FrameNotFoundError if no frame with the given URI exists.

Source
frame_content(id : UInt64) : String

Gets the text content of a frame by ID.

Raises FrameNotFoundError if the frame does not exist.

Source
frame_count

Returns the number of frames in the memory.

Source
put(content : String, options : PutOptions | Nil = nil) : UInt64

Adds string content to the memory.

Returns the frame ID of the newly created frame.

Source
put(data : Bytes, options : PutOptions | Nil = nil) : UInt64

Adds binary content to the memory.

Returns the frame ID of the newly created frame.

Source
search(query : String, top_k : Int32 = 10) : SearchResponse

Searches the memory with the given query string.

This is a convenience method that creates a SearchRequest with defaults.

Source
search(request : SearchRequest) : SearchResponse

Searches the memory with a SearchRequest.

Source
stats

Returns memory statistics.

Source
timeline(query : TimelineQuery | Nil = nil) : TimelineResponse

Queries the timeline (chronological frame list).

Returns frames in chronological order (or reverse if specified).

Source