Class: OllamaChat::Database::Models::Collection
- Inherits:
-
Object
- Object
- OllamaChat::Database::Models::Collection
- Includes:
- Duplicatable
- Defined in:
- lib/ollama_chat/database/models/collection.rb
Overview
Represents a document collection stored in the database, allowing for dynamic management of documentrix collections.
This model stores collections with a name, description, and patterns for automatic file discovery and synchronization.
Instance Attribute Summary collapse
-
#chat ⇒ Object
writeonly
Sets the chat instance associated with this collection.
Class Method Summary collapse
-
.sync(chat) ⇒ Object
Synchronizes the database records with the Documentrix collections.
Instance Method Summary collapse
-
#after_destroy ⇒ Object
Hook to clean up the corresponding Documentrix collection when the database record is destroyed.
-
#created_at(value) ⇒ Time?
The timestamp when the collection was created.
-
#description(value) ⇒ String?
A description of the collection.
-
#id(value) ⇒ Integer
The primary key for the collection entry.
-
#name(value) ⇒ String
The name of the collection (matches documentrix name).
-
#patterns(value) ⇒ Array?
An array of glob patterns for file discovery.
-
#updated_at(value) ⇒ Time?
The timestamp of the last update to the collection.
-
#validate ⇒ Object
Validates the collection.
Methods included from Duplicatable
Instance Attribute Details
#chat=(value) ⇒ Object (writeonly)
Sets the chat instance associated with this collection.
This allows the collection to interact with the chat's document store during lifecycle events, such as cleanup upon destruction.
29 30 31 |
# File 'lib/ollama_chat/database/models/collection.rb', line 29 def chat=(value) @chat = value end |
Class Method Details
.sync(chat) ⇒ Object
Synchronizes the database records with the Documentrix collections.
This method iterates through the configured collections in the chat's document store and ensures that every collection has a corresponding record in the database. If a collection exists in Documentrix but not in the database, a new record is created with a default description.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ollama_chat/database/models/collection.rb', line 53 def self.sync(chat) chat.documents.collections.each do |name| where(name: name.to_s).first and next create( name: name.to_s, description: "TODO: Describe collection #{name}", patterns: [] ) end end |
Instance Method Details
#after_destroy ⇒ Object
Hook to clean up the corresponding Documentrix collection when the database record is destroyed.
This ensures that we don't leave orphaned vector data in the Documentrix engine when the underlying collection record is removed.
36 37 38 39 40 41 42 43 |
# File 'lib/ollama_chat/database/models/collection.rb', line 36 def after_destroy super @chat or return @chat.switch_collection(name) do @chat.documents.clear end true end |
#created_at=(value) ⇒ Time?
Returns The timestamp when the collection was created.
|
|
# File 'lib/ollama_chat/database/models/collection.rb', line 64
|
#description=(value) ⇒ String?
Returns A description of the collection.
|
|
# File 'lib/ollama_chat/database/models/collection.rb', line 64
|
#id=(value) ⇒ Integer
Returns The primary key for the collection entry.
|
|
# File 'lib/ollama_chat/database/models/collection.rb', line 64
|
#name=(value) ⇒ String
Returns The name of the collection (matches documentrix name).
|
|
# File 'lib/ollama_chat/database/models/collection.rb', line 64
|
#patterns=(value) ⇒ Array?
Returns An array of glob patterns for file discovery.
|
|
# File 'lib/ollama_chat/database/models/collection.rb', line 64
|
#updated_at=(value) ⇒ Time?
Returns The timestamp of the last update to the collection.
|
|
# File 'lib/ollama_chat/database/models/collection.rb', line 64
|
#validate ⇒ Object
Validates the collection.
Ensures that the name is present and unique.
16 17 18 19 20 21 |
# File 'lib/ollama_chat/database/models/collection.rb', line 16 def validate super validates_presence :name validates_unique :name validates_presence :description end |