Class: Phronomy::KnowledgeSource::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/knowledge_source/base.rb

Overview

Abstract base class for all KnowledgeSource implementations.

Subclasses must implement #fetch(query:) and return an Array of chunk Hashes. Each chunk Hash must contain: :content [String] the text to inject into the context :type [Symbol] semantic tag (e.g. :static, :rag, :entity)

Direct Known Subclasses

EntityKnowledge, RAGKnowledge, StaticKnowledge

Instance Method Summary collapse

Instance Method Details

#fetch(query: nil, cancellation_token: nil) ⇒ Array<Hash>

Retrieve knowledge chunks relevant to the given query.

Parameters:

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

    the current user input used to select relevant chunks

  • cancellation_token (Phronomy::CancellationToken, nil) (defaults to: nil)

    optional token; raises CancellationError when cancelled

Returns:

  • (Array<Hash>)

    array of { content: String, type: Symbol }

Raises:

  • (NotImplementedError)


18
19
20
21
# File 'lib/phronomy/knowledge_source/base.rb', line 18

def fetch(query: nil, cancellation_token: nil)
  cancellation_token&.raise_if_cancelled!
  raise NotImplementedError, "#{self.class}#fetch is not implemented"
end

#fetch_async(query: nil, cancellation_token: nil, timeout: nil) ⇒ BlockingAdapterPool::PendingOperation

Submits a #fetch call to BlockingAdapterPool and returns a BlockingAdapterPool::PendingOperation. Callers can fan out multiple fetches in parallel and await them all.

Parameters:

  • query (String, nil) (defaults to: nil)
  • cancellation_token (Phronomy::CancellationToken, nil) (defaults to: nil)
  • timeout (Numeric, nil) (defaults to: nil)

    seconds before the operation is abandoned

Returns:



32
33
34
35
36
37
38
39
# File 'lib/phronomy/knowledge_source/base.rb', line 32

def fetch_async(query: nil, cancellation_token: nil, timeout: nil)
  Phronomy::Runtime.instance.blocking_io.submit(
    timeout: timeout,
    cancellation_token: cancellation_token
  ) do
    fetch(query: query, cancellation_token: cancellation_token)
  end
end

#static?Boolean

Returns true when this source's content is considered static (i.e. does not change between agent invocations). Static sources are eligible for fingerprint-based caching in ContextVersionCache.

Override in subclasses that return fixed content.

Returns:

  • (Boolean)


49
50
51
# File 'lib/phronomy/knowledge_source/base.rb', line 49

def static?
  false
end