Module: OllamaChat::RAGHandling

Included in:
Chat
Defined in:
lib/ollama_chat/rag_handling.rb

Overview

A module that handles Retrieval-Augmented Generation (RAG) operations for the OllamaChat application.

This module provides functionality for managing collections, clearing and changing collections, listing collections, and renaming collections within the RAG system.

Instance Method Summary collapse

Instance Method Details

#switch_collection(other_collection = nil) { ... } ⇒ Object

Temporarily switches the RAG collection to the specified collection.

The current collection is stored and restored after the block is executed, ensuring the state remains consistent regardless of whether the block completes successfully or raises an error.

Parameters:

  • other_collection (String, nil) (defaults to: nil)

    the collection to switch to. If nil, the current collection is used.

Yields:

  • The code to execute within the context of the switched collection.

Returns:

  • (Object)

    the result of the block.



18
19
20
21
22
23
24
# File 'lib/ollama_chat/rag_handling.rb', line 18

def switch_collection(other_collection = nil)
  other_collection ||= collection
  old_collection, @documents.collection = collection, other_collection
  yield other_collection
ensure
  @documents.collection = old_collection
end