Skip to main content

brainwires_core/
search.rs

1//! Shared search types used across the RAG, vector DB, and spectral modules.
2//!
3//! These types live in core because they are needed by both `brainwires-storage`
4//! (the vector DB layer) and `brainwires-cognition` (the RAG / indexer layer).
5
6use serde::{Deserialize, Serialize};
7
8/// A single search result from vector or hybrid search.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
11pub struct SearchResult {
12    /// File path relative to the indexed root.
13    pub file_path: String,
14    /// Absolute path to the indexed root directory.
15    #[serde(default)]
16    pub root_path: Option<String>,
17    /// The code chunk content.
18    pub content: String,
19    /// Combined similarity score (0.0 to 1.0).
20    pub score: f32,
21    /// Vector similarity score (0.0 to 1.0).
22    pub vector_score: f32,
23    /// Keyword match score (0.0 to 1.0) — only present in hybrid search.
24    pub keyword_score: Option<f32>,
25    /// Starting line number in the file.
26    pub start_line: usize,
27    /// Ending line number in the file.
28    pub end_line: usize,
29    /// Programming language detected.
30    pub language: String,
31    /// Optional project name for multi-project support.
32    pub project: Option<String>,
33    /// Timestamp when the chunk was indexed (Unix epoch seconds).
34    /// For git commits this equals the commit date.
35    #[serde(default)]
36    pub indexed_at: i64,
37}
38
39/// Metadata stored with each code chunk in the vector database.
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct ChunkMetadata {
42    /// File path relative to indexed root.
43    pub file_path: String,
44    /// Absolute path to the indexed root directory.
45    #[serde(default)]
46    pub root_path: Option<String>,
47    /// Project name (for multi-project support).
48    pub project: Option<String>,
49    /// Starting line number.
50    pub start_line: usize,
51    /// Ending line number.
52    pub end_line: usize,
53    /// Programming language.
54    pub language: Option<String>,
55    /// File extension.
56    pub extension: Option<String>,
57    /// SHA256 hash of the file content.
58    pub file_hash: String,
59    /// Timestamp when indexed.
60    pub indexed_at: i64,
61}
62
63/// Statistics about the vector database contents.
64#[derive(Debug, Clone, Default)]
65pub struct DatabaseStats {
66    /// Total number of stored points.
67    pub total_points: usize,
68    /// Total number of vectors.
69    pub total_vectors: usize,
70    /// Breakdown of indexed chunks by programming language.
71    pub language_breakdown: Vec<(String, usize)>,
72}