Class: SwarmMemory::Adapters::Base
- Inherits:
-
Object
- Object
- SwarmMemory::Adapters::Base
- Defined in:
- lib/swarm_memory/adapters/base.rb
Overview
Abstract base adapter interface for memory storage backends
Subclasses must implement all public methods to provide different storage backends (filesystem, Redis, SQLite, etc.)
Direct Known Subclasses
Constant Summary collapse
- MAX_ENTRY_SIZE =
Maximum size per entry (3MB)
3_000_000- MAX_TOTAL_SIZE =
Maximum total storage size (100GB)
100_000_000_000
Instance Method Summary collapse
-
#clear ⇒ void
Clear all entries.
-
#delete(file_path:) ⇒ void
Delete a specific entry.
-
#glob(pattern:) ⇒ Array<Hash>
Search entries by glob pattern.
-
#grep(pattern:, case_insensitive: false, output_mode: "files_with_matches", path: nil) ⇒ Array<Hash>, String
Search entry content by pattern.
-
#list(prefix: nil) ⇒ Array<Hash>
List entries, optionally filtered by prefix.
-
#read(file_path:) ⇒ String
Read content from storage.
-
#read_entry(file_path:) ⇒ Core::Entry
Read full entry with metadata.
-
#semantic_search(embedding:, top_k: 10, threshold: 0.0) ⇒ Array<Hash>
Semantic search by embedding vector.
-
#size ⇒ Integer
Get number of entries.
-
#total_size ⇒ Integer
Get current total size.
-
#write(file_path:, content:, title:, embedding: nil, metadata: nil) ⇒ Core::Entry
Write content to storage.
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
Clear all entries
86 87 88 |
# File 'lib/swarm_memory/adapters/base.rb', line 86 def clear raise NotImplementedError, "Subclass must implement #clear" end |
#delete(file_path:) ⇒ void
This method returns an undefined value.
Delete a specific entry
52 53 54 |
# File 'lib/swarm_memory/adapters/base.rb', line 52 def delete(file_path:) raise NotImplementedError, "Subclass must implement #delete" end |
#glob(pattern:) ⇒ Array<Hash>
Search entries by glob pattern
68 69 70 |
# File 'lib/swarm_memory/adapters/base.rb', line 68 def glob(pattern:) raise NotImplementedError, "Subclass must implement #glob" end |
#grep(pattern:, case_insensitive: false, output_mode: "files_with_matches", path: nil) ⇒ Array<Hash>, String
Search entry content by pattern
79 80 81 |
# File 'lib/swarm_memory/adapters/base.rb', line 79 def grep(pattern:, case_insensitive: false, output_mode: "files_with_matches", path: nil) raise NotImplementedError, "Subclass must implement #grep" end |
#list(prefix: nil) ⇒ Array<Hash>
List entries, optionally filtered by prefix
60 61 62 |
# File 'lib/swarm_memory/adapters/base.rb', line 60 def list(prefix: nil) raise NotImplementedError, "Subclass must implement #list" end |
#read(file_path:) ⇒ String
Read content from storage
34 35 36 |
# File 'lib/swarm_memory/adapters/base.rb', line 34 def read(file_path:) raise NotImplementedError, "Subclass must implement #read" end |
#read_entry(file_path:) ⇒ Core::Entry
Read full entry with metadata
43 44 45 |
# File 'lib/swarm_memory/adapters/base.rb', line 43 def read_entry(file_path:) raise NotImplementedError, "Subclass must implement #read_entry" end |
#semantic_search(embedding:, top_k: 10, threshold: 0.0) ⇒ Array<Hash>
Semantic search by embedding vector
Searches all entries with embeddings and returns those similar to the query. Results are sorted by cosine similarity in descending order.
Each result hash must contain:
- :path (String) - logical file path
- :similarity (Float) - cosine similarity score 0.0-1.0
- :title (String) - entry title
- :size (Integer) - content size in bytes
- :updated_at (Time) - last update
- :metadata (Hash) - nested hash with type, , domain, etc.
128 129 130 |
# File 'lib/swarm_memory/adapters/base.rb', line 128 def semantic_search(embedding:, top_k: 10, threshold: 0.0) raise NotImplementedError, "Subclass must implement #semantic_search" end |
#size ⇒ Integer
Get number of entries
100 101 102 |
# File 'lib/swarm_memory/adapters/base.rb', line 100 def size raise NotImplementedError, "Subclass must implement #size" end |
#total_size ⇒ Integer
Get current total size
93 94 95 |
# File 'lib/swarm_memory/adapters/base.rb', line 93 def total_size raise NotImplementedError, "Subclass must implement #total_size" end |
#write(file_path:, content:, title:, embedding: nil, metadata: nil) ⇒ Core::Entry
Write content to storage
25 26 27 |
# File 'lib/swarm_memory/adapters/base.rb', line 25 def write(file_path:, content:, title:, embedding: nil, metadata: nil) raise NotImplementedError, "Subclass must implement #write" end |