project_rag/relations/storage/
mod.rs

1//! Storage layer for code relationships.
2//!
3//! This module provides persistent storage for definitions and references
4//! using LanceDB tables.
5
6mod lance_store;
7
8pub use lance_store::LanceRelationsStore;
9
10use anyhow::Result;
11use async_trait::async_trait;
12
13use crate::relations::types::{CallEdge, Definition, Reference};
14
15/// Trait for storing and querying code relationships.
16#[async_trait]
17pub trait RelationsStore: Send + Sync {
18    /// Store definitions for a file
19    async fn store_definitions(
20        &self,
21        definitions: Vec<Definition>,
22        root_path: &str,
23    ) -> Result<usize>;
24
25    /// Store references for a file
26    async fn store_references(&self, references: Vec<Reference>, root_path: &str) -> Result<usize>;
27
28    /// Find definition at a specific location
29    async fn find_definition_at(
30        &self,
31        file_path: &str,
32        line: usize,
33        column: usize,
34    ) -> Result<Option<Definition>>;
35
36    /// Find all definitions with a given name
37    async fn find_definitions_by_name(&self, name: &str) -> Result<Vec<Definition>>;
38
39    /// Find all references to a symbol
40    async fn find_references(&self, target_symbol_id: &str) -> Result<Vec<Reference>>;
41
42    /// Get callers of a function (incoming call edges)
43    async fn get_callers(&self, symbol_id: &str) -> Result<Vec<CallEdge>>;
44
45    /// Get callees of a function (outgoing call edges)
46    async fn get_callees(&self, symbol_id: &str) -> Result<Vec<CallEdge>>;
47
48    /// Delete all relationships for a file (for incremental updates)
49    async fn delete_by_file(&self, file_path: &str) -> Result<usize>;
50
51    /// Clear all relationships
52    async fn clear(&self) -> Result<()>;
53
54    /// Get statistics
55    async fn get_stats(&self) -> Result<RelationsStats>;
56}
57
58/// Statistics about stored relationships
59#[derive(Debug, Clone, Default)]
60pub struct RelationsStats {
61    /// Total number of definitions
62    pub definition_count: usize,
63    /// Total number of references
64    pub reference_count: usize,
65    /// Number of unique files with definitions
66    pub files_with_definitions: usize,
67}