Skip to main content

KnowledgeGraph

Struct KnowledgeGraph 

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

Knowledge Graph Manager - main entry point for the library.

Implementations§

Source§

impl KnowledgeGraph

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open a new knowledge graph database connection.

Source

pub fn open_in_memory() -> Result<Self>

Open an in-memory knowledge graph (useful for testing).

Source

pub fn connection(&self) -> &Connection

Get a reference to the underlying SQLite connection.

Source

pub fn transaction(&self) -> Result<Transaction<'_>>

Begin a transaction for batch operations.

Source

pub fn insert_entity(&self, entity: &Entity) -> Result<i64>

Insert an entity into the knowledge graph.

Source

pub fn get_entity(&self, id: i64) -> Result<Entity>

Get an entity by ID.

Source

pub fn list_entities( &self, entity_type: Option<&str>, limit: Option<i64>, ) -> Result<Vec<Entity>>

List entities with optional filtering.

Source

pub fn update_entity(&self, entity: &Entity) -> Result<()>

Update an entity.

Source

pub fn delete_entity(&self, id: i64) -> Result<()>

Delete an entity.

Source

pub fn insert_relation(&self, relation: &Relation) -> Result<i64>

Insert a relation between entities.

Source

pub fn get_neighbors(&self, entity_id: i64, depth: u32) -> Result<Vec<Neighbor>>

Get neighbors of an entity using BFS traversal.

Source

pub fn insert_vector(&self, entity_id: i64, vector: Vec<f32>) -> Result<()>

Insert a vector embedding for an entity.

Source

pub fn search_vectors( &self, query: Vec<f32>, k: usize, ) -> Result<Vec<SearchResult>>

Search for similar entities using vector embeddings.

Source

pub fn create_turboquant_index( &self, config: Option<TurboQuantConfig>, ) -> Result<TurboQuantIndex>

Create a TurboQuant index for fast approximate nearest neighbor search.

TurboQuant provides:

  • Instant indexing (no training required)
  • 6x memory compression
  • Near-zero accuracy loss
§Arguments
  • config - Optional configuration (uses defaults if None)
§Example
let config = TurboQuantConfig {
    dimension: 384,
    bit_width: 3,
    seed: 42,
};
let mut index = kg.create_turboquant_index(Some(config))?;

// Add vectors to index
for (entity_id, vector) in all_vectors {
    index.add_vector(entity_id, &vector)?;
}

// Fast search
let results = index.search(&query_vector, 10)?;
Source

pub fn build_turboquant_index( &self, config: Option<TurboQuantConfig>, ) -> Result<TurboQuantIndex>

Build a TurboQuant index from all existing vectors in the database. This is a convenience method that loads all vectors and indexes them.

Semantic search using vector embeddings. Returns entities sorted by similarity score.

Source

pub fn kg_get_context(&self, entity_id: i64, depth: u32) -> Result<GraphContext>

Get context around an entity using graph traversal. Returns neighbors up to the specified depth.

Hybrid search combining semantic search and graph context. Performs semantic search first, then retrieves context for top-k results.

Source

pub fn kg_bfs_traversal( &self, start_id: i64, direction: Direction, max_depth: u32, ) -> Result<Vec<TraversalNode>>

BFS traversal from a starting entity. Returns all reachable entities within max_depth with depth information.

Source

pub fn kg_dfs_traversal( &self, start_id: i64, direction: Direction, max_depth: u32, ) -> Result<Vec<TraversalNode>>

DFS traversal from a starting entity. Returns all reachable entities within max_depth.

Source

pub fn kg_shortest_path( &self, from_id: i64, to_id: i64, max_depth: u32, ) -> Result<Option<TraversalPath>>

Find shortest path between two entities using BFS. Returns the path with all intermediate steps (if exists).

Source

pub fn kg_graph_stats(&self) -> Result<GraphStats>

Compute graph statistics.

Source

pub fn kg_pagerank( &self, config: Option<PageRankConfig>, ) -> Result<Vec<(i64, f64)>>

Compute PageRank scores for all entities. Returns a vector of (entity_id, score) sorted by score descending.

Source

pub fn kg_louvain(&self) -> Result<CommunityResult>

Detect communities using Louvain algorithm. Returns community memberships and modularity score.

Source

pub fn kg_connected_components(&self) -> Result<Vec<Vec<i64>>>

Find connected components in the graph. Returns a list of components, each being a list of entity IDs.

Source

pub fn kg_analyze(&self) -> Result<GraphAnalysis>

Run full graph analysis (PageRank + Louvain + Connected Components).

Trait Implementations§

Source§

impl Debug for KnowledgeGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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.

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, 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