RuvLLMEngine

Struct RuvLLMEngine 

Source
pub struct RuvLLMEngine { /* private fields */ }
Expand description

Main RuvLLM engine for LLM inference with intelligent memory.

The RuvLLMEngine is the primary entry point for RuvLLM, providing:

  • Session Management: Create and manage user sessions with state persistence
  • Policy Storage: Ruvector-backed semantic search for runtime policies
  • Adapter Management: Hot-swapping LoRA adapters for task-specific tuning
  • Witness Logging: Audit trail with HNSW-indexed semantic search
  • SONA Learning: Three-tier continuous learning integration

§Example

use ruvllm::{RuvLLMEngine, RuvLLMConfig};

// Create engine with configuration
let config = RuvLLMConfig::default();
let engine = RuvLLMEngine::new(config)?;

// Create a session for a user
let session = engine.create_session(Some("user-123"))?;

// Search for relevant policies
let embedding = compute_embedding("code completion task");
let policies = engine.search_policies(&embedding, 5)?;

// Record audit entry
let entry = WitnessEntry::new("completion", latency, routing);
engine.record_witness(entry)?;

§Architecture

+-------------------+     +-------------------+
| RuvLLMEngine      |---->| PolicyStore       |
|                   |     | (Ruvector)        |
|                   |     +-------------------+
|                   |
|                   |---->| SessionIndex      |
|                   |     | (Ruvector)        |
|                   |     +-------------------+
|                   |
|                   |---->| WitnessLog        |
|                   |     | (HNSW search)     |
+-------------------+     +-------------------+

Implementations§

Source§

impl RuvLLMEngine

Source

pub fn new(config: RuvLLMConfig) -> Result<Self>

Create a new RuvLLM engine with the given configuration.

This initializes all subsystems including:

  • Policy store for learned thresholds
  • Session index for conversation state
  • Witness log for audit trails
  • SONA integration for learning loops
§Arguments
  • config - Engine configuration
§Errors

Returns an error if storage paths cannot be created or initialized.

§Example
use ruvllm::{RuvLLMEngine, RuvLLMConfig};

let engine = RuvLLMEngine::new(RuvLLMConfig::default())?;
Source

pub fn create_session(&self, user_id: Option<&str>) -> Result<Session>

Create a new session for a user.

Sessions track conversation state, KV cache references, and enable multi-turn interactions. Each session is automatically indexed in Ruvector for semantic retrieval.

§Arguments
  • user_id - Optional user identifier for session tracking
§Returns

A new Session instance with a unique ID.

§Example
// Anonymous session
let session = engine.create_session(None)?;

// User-identified session
let session = engine.create_session(Some("user-123"))?;
println!("Session ID: {}", session.id());
Source

pub fn get_session(&self, session_id: &str) -> Result<Option<Session>>

Get session by ID

Source

pub fn search_policies( &self, context_embedding: &[f32], limit: usize, ) -> Result<Vec<PolicyEntry>>

Search for policies matching the given context embedding.

Uses HNSW-indexed semantic search to find relevant policies (quantization settings, routing rules, etc.) based on the current request context.

§Arguments
  • context_embedding - Vector embedding of the current context
  • limit - Maximum number of policies to return
§Returns

Vector of matching PolicyEntry items, sorted by relevance.

§Example
let context = compute_embedding("code completion for Python");
let policies = engine.search_policies(&context, 5)?;

for policy in policies {
    println!("Policy: {:?}, score: {}", policy.policy_type, policy.score);
}
Source

pub fn record_witness(&self, entry: WitnessEntry) -> Result<()>

Record a witness entry for audit logging.

Witness entries provide an audit trail of inference decisions, including latency breakdowns, routing decisions, and quality scores. All entries are HNSW-indexed for semantic search.

§Arguments
  • entry - The witness entry to record
§Example
use ruvllm::{WitnessEntry, LatencyBreakdown, RoutingDecision};

let entry = WitnessEntry {
    session_id: session.id().to_string(),
    request_type: "completion".to_string(),
    latency: LatencyBreakdown {
        prefill_ms: 45.0,
        decode_ms: 120.0,
        total_ms: 165.0,
    },
    routing: RoutingDecision::default(),
    ..Default::default()
};

engine.record_witness(entry)?;
Source

pub fn search_witness( &self, query_embedding: &[f32], limit: usize, ) -> Result<Vec<WitnessEntry>>

Search witness logs semantically

Source

pub fn sona(&self) -> &SonaIntegration

Get the SONA integration for learning

Source

pub fn adapters(&self) -> &AdapterManager

Get the adapter manager

Source

pub fn policies(&self) -> &PolicyStore

Get the policy store

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,