PostgresIndexBackend

Struct PostgresIndexBackend 

Source
pub struct PostgresIndexBackend {
    pool: Pool,
    table_name: String,
}
Expand description

PostgreSQL-based index backend.

Uses deadpool_postgres::Pool for thread-safe connection pooling, enabling &self methods without interior mutability wrappers.

Fields§

§pool: Pool

Connection pool (thread-safe via internal Arc).

§table_name: String

Table name for memories (validated against whitelist).

Implementations§

Source§

impl PostgresIndexBackend

Source

const POOL_MAX_SIZE: usize = 20usize

Maximum connections in pool (CHAOS-H1).

Source

pub fn new(connection_url: &str, table_name: impl Into<String>) -> Result<Self>

Creates a new PostgreSQL index backend with TLS encryption (COMP-C3).

Uses rustls for TLS connections. The connection URL should include sslmode=require or sslmode=verify-full for production use.

§Errors

Returns an error if the connection pool fails to initialize, if TLS configuration fails, or if the table name is not allowed.

Source

fn root_cert_store() -> RootCertStore

Builds root certificate store for TLS.

Source

fn parse_connection_url(url: &str) -> Result<Config>

Parses the connection URL into a tokio-postgres config (SEC-M2).

Validates the URL for security before parsing to prevent injection attacks.

Source

fn host_to_string(h: &Host) -> String

Extracts host string from tokio-postgres Host.

Source

fn build_pool_config(config: &Config) -> Config

Builds a deadpool config from tokio-postgres config.

§Pool Exhaustion Protection (CHAOS-H1)

Configures connection pool with safety limits:

  • Max 20 connections (prevents pool exhaustion)
  • Runtime pool builder sets timeouts for wait/create/recycle
§Statement Caching (DB-H4)

Statement caching is handled automatically by tokio-postgres connections. Each connection maintains its own prepared statement cache. The RecyclingMethod::Fast setting preserves connections (and their statement caches) across uses, providing implicit statement caching without additional configuration.

Source

pub fn with_defaults() -> Result<Self>

Creates a backend with default settings.

§Errors

Returns an error if the connection fails.

Source

fn block_on<F, T>(&self, f: F) -> Result<T>
where F: Future<Output = Result<T>>,

Runs a blocking operation on the async pool.

Source

fn run_migrations(&self) -> Result<()>

Runs migrations.

Source

fn build_where_clause( filter: &SearchFilter, start_param: i32, ) -> (String, Vec<String>)

Builds WHERE clause for filters.

Source

fn add_namespace_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )

Adds namespace filter to WHERE clause.

Source

fn add_domain_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )

Adds domain filter to WHERE clause.

Source

fn add_status_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )

Adds status filter to WHERE clause.

Source

fn add_project_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )

Source

fn add_branch_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )

Source

fn add_file_path_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )

Source

async fn index_async(&self, memory: &Memory) -> Result<()>

Async implementation of index operation.

Source

async fn remove_async(&self, id: &MemoryId) -> Result<bool>

Async implementation of remove operation.

Source

async fn search_async( &self, query: &str, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>

Async implementation of search operation.

Source

async fn list_all_async( &self, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>

Async implementation of list_all operation.

Source

async fn clear_async(&self) -> Result<()>

Async implementation of clear operation.

Trait Implementations§

Source§

impl IndexBackend for PostgresIndexBackend

Source§

fn index(&self, memory: &Memory) -> Result<()>

Indexes a memory for full-text search. Read more
Source§

fn remove(&self, id: &MemoryId) -> Result<bool>

Removes a memory from the index. Read more
Source§

fn search( &self, query: &str, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>

Searches for memories matching a text query. Read more
Source§

fn list_all( &self, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>

Lists all indexed memories, optionally filtered. Read more
Source§

fn get_memory(&self, _id: &MemoryId) -> Result<Option<Memory>>

Retrieves a memory by ID. Read more
Source§

fn clear(&self) -> Result<()>

Clears the entire index. Read more
Source§

fn reindex(&self, memories: &[Memory]) -> Result<()>

Re-indexes all memories. Read more
Source§

fn get_memories_batch(&self, ids: &[MemoryId]) -> Result<Vec<Option<Memory>>>

Retrieves multiple memories by their IDs in a single batch query. Read more

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.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

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

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

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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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