Class: Pikuri::VectorDb::Server::InMemory
- Inherits:
-
Object
- Object
- Pikuri::VectorDb::Server::InMemory
- Defined in:
- lib/pikuri/vector_db/server/in_memory.rb
Overview
The null supervisor — the in-process implementation of the Server
protocol (InMemory.ensure_running / #client / #close) that Qdrant and
Chroma implement over docker. No container, no process: it owns the
Backend::InMemory stores' lifetime the way the docker supervisors own
a container, which is what lets bin/pikuri-corpus pick a Server
class, call ensure_running.client(...), and close it identically for
all three engines.
#client(collection:) memoizes one store per collection name (same name
→ same store, so the Watcher and agent share one index), guarded by a
Monitor so clients mint from any thread. #close empties every store
and clears the registry — outstanding clients keep working but go
empty, mirroring the docker servers removing the container under the
client's feet (degraded and visible, never silently stale). #ensure_running!
is a no-op and deliberately does NOT register with Finalizers —
process exit reclaims RAM, so a no-op teardown would be ceremony.
Class Method Summary collapse
-
.ensure_running ⇒ InMemory
Construct a server and "ensure it's running" — a no-op for RAM, present so call sites can treat all three Server classes identically (+server_class.ensure_running.client(...)+).
Instance Method Summary collapse
-
#client(collection:) ⇒ Backend::InMemory
Fetch-or-create the Backend::InMemory store for
collection. -
#close ⇒ void
Empty every store and clear the registry.
-
#ensure_running! ⇒ InMemory
No-op (nothing to boot); returns self so the
ensure_running.client(...)chain works. - #initialize ⇒ InMemory constructor
Constructor Details
#initialize ⇒ InMemory
36 37 38 39 |
# File 'lib/pikuri/vector_db/server/in_memory.rb', line 36 def initialize @collections = {} @lock = Monitor.new end |
Class Method Details
.ensure_running ⇒ InMemory
Construct a server and "ensure it's running" — a no-op for RAM, present so call sites can treat all three Server classes identically (+server_class.ensure_running.client(...)+).
31 32 33 |
# File 'lib/pikuri/vector_db/server/in_memory.rb', line 31 def self.ensure_running(**) new.ensure_running! end |
Instance Method Details
#client(collection:) ⇒ Backend::InMemory
Fetch-or-create the Backend::InMemory store for
collection. Same name → same store; the registry
persists until #close.
57 58 59 60 61 62 63 |
# File 'lib/pikuri/vector_db/server/in_memory.rb', line 57 def client(collection:) raise ArgumentError, 'collection must be non-empty' if collection.nil? || collection.to_s.empty? @lock.synchronize do @collections[collection] ||= Backend::InMemory.new end end |
#close ⇒ void
This method returns an undefined value.
Empty every store and clear the registry. Outstanding clients return no hits afterwards (see the class header). Idempotent; safe to call directly at host teardown.
70 71 72 73 74 75 76 |
# File 'lib/pikuri/vector_db/server/in_memory.rb', line 70 def close @lock.synchronize do @collections.each_value(&:delete_all) @collections.clear end nil end |
#ensure_running! ⇒ InMemory
No-op (nothing to boot); returns self so the
ensure_running.client(...) chain works.
45 46 47 |
# File 'lib/pikuri/vector_db/server/in_memory.rb', line 45 def ensure_running! self end |