Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

feat: allow ov tui to show all vector records in vikingdb (#626)

MaojiaSheng102b8aa6fc88
diff --git a/crates/ov_cli/src/client.rs b/crates/ov_cli/src/client.rs
index b23121950..a03232ba0 100644
--- a/crates/ov_cli/src/client.rs
+++ b/crates/ov_cli/src/client.rs
@@ -734,4 +734,48 @@ impl HttpClient {
);
self.post(&path, &serde_json::json!({})).await
}
+
+ // ============ Debug Vector Methods ============
+
+ /// Get paginated vector records
+ pub async fn debug_vector_scroll(
+ &self,
+ limit: Option<u32>,
+ cursor: Option<String>,
+ ) -> Result<(Vec<serde_json::Value>, Option<String>)> {
+ let mut params = Vec::new();
+ if let Some(l) = limit {
+ params.push(("limit".to_string(), l.to_string()));
+ }
+ if let Some(c) = cursor {
+ params.push(("cursor".to_string(), c));
+ }
+
+ let result: serde_json::Value = self.get("/api/v1/debug/vector/scroll", &params).await?;
+ let records = result["records"]
+ .as_array()
+ .ok_or_else(|| Error::Parse("Missing records in response".to_string()))?
+ .clone();
+ let next_cursor = result["next_cursor"].as_str().map(|s| s.to_string());
+
+ Ok((records, next_cursor))
+ }
+
+ /// Get count of vector records
+ pub async fn debug_vector_count(
+ &self,
+ filter: Option<&serde_json::Value>,
+ ) -> Result<u64> {
+ let mut params = Vec::new();
+ if let Some(f) = filter {
+ params.push(("filter".to_string(), serde_json::to_string(f)?));
+ }
+
+ let result: serde_json::Value = self.get("/api/v1/debug/vector/count", &params).await?;
+ let count = result["count"]
+ .as_u64()
+ .ok_or_else(|| Error::Parse("Missing count in response".to_string()))?;
+
+ Ok(count)
+ }
}
diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rs
index 3aca6ddec..81126ae96 100644
--- a/crates/ov_cli/src/main.rs
+++ b/crates/ov_cli/src/main.rs
@@ -333,8 +333,8 @@ enum Commands {
},
/// Interactive TUI file explorer
Tui {
- /// Viking URI to start browsing (default: viking://)
- #[arg(default_value = "viking://")]
+ /// Viking URI to start browsing (default: /)
+ #[arg(default_value = "/")]
uri: String,
},
/// Chat with vikingbot agent
diff --git a/crates/ov_cli/src/tui/app.rs b/crates/ov_cli/src/tui/app.rs
index 1039f5a0e..e2c5bb461 100644
--- a/crates/ov_cli/src/tui/app.rs
+++ b/crates/ov_cli/src/tui/app.rs
@@ -8,6 +8,41 @@ pub enum Panel {
Content,
}
+#[derive(Debug, Clone)]
+pub struct VectorRecordsState {
+ pub records: Vec<serde_json::Value>,
+ pub cursor: usize,
+ pub scroll_offset: usize,
+ pub next_page_cursor: Option<String>,
+ pub has_more: bool,
+ pub total_count: Option<u64>,
+}
+
+impl VectorRecordsState {
+ pub fn new() -> Self {
+ Self {
+ records: Vec::new(),
+ cursor: 0,
+ scroll_offset: 0,
+ next_page_cursor: None,
+ has_more: false,
+ total_count: None,
+ }
+ }
+
+ /// Adjust scroll_offset so cursor is visible in the given viewport height
+ pub fn adjust_scroll(&mut self, viewport_height: usize) {
+ if viewport_height == 0 {
+ return;
+ }
+ if self.cursor < self.scroll_offset {
+ self.scroll_offset = self.cursor;
+ } else if self.cursor >= self.scroll_offset + viewport_height {
+ self.scroll_offset = self.cursor - viewport_height + 1;
+ }
+ }
+}
+
pub struct App {
pub client: HttpClient,
pub tree: TreeState,
@@ -18,6 +53,8 @@ pub struct App {
pub content_line_count: u16,
pub should_quit: bool,
pub status_message: String,
+ pub vector_state: VectorRecordsState,
+ pub showing_vector_records: bool,
}
impl App {
@@ -32,6 +69,8 @@ impl App {
content_line_count: 0,
should_quit: false,
status_message: String::new(),
+ vector_state: VectorRecordsState::new(),
+ showing_vector_records: false,
}
}
@@ -157,4 +196,89 @@ impl App {
Panel::Content => Panel::Tree,
};
}
+
+ pub async fn load_vector_records(&mut self) {
+ self.status_message = "Loading vector records...".to_string();
+ match self.client.debug_vector_scroll(Some(100), None).await {
+ Ok((records, next_cursor)) => {
+ self.vector_state.records = records;
+ self.vector_state.has_more = next_cursor.is_some();
+ self.vector_state.next_page_cursor = next_cursor;
+ self.vector_state.cursor = 0;
+ self.vector_state.scroll_offset = 0;
+ self.status_message = format!("Loaded {} vector records", self.vector_state.records.len());
+ }
+ Err(e) => {
+ self.status_message = format!("Failed to load vector records: {}", e);
+ }
+ }
+ }
+
+ pub async fn load_next_vector_page(&mut self) {
+ if !self.vector_state.has_more {
+ self.status_message = "No more pages".to_string();
+ return;
+ }
+
+ self.status_message = "Loading next page...".to_string();
+ match self
+ .client
+ .debug_vector_scroll(Some(100), self.vector_state.next_page_cursor.clone())
+ .await
+ {
+ Ok((mut new_records, next_cursor)) => {
+ self.vector_state.records.append(&mut new_records);
+ self.vector_state.has_more = next_cursor.is_some();
+ self.vector_state.next_page_cursor = next_cursor;
+ self.status_message = format!("Loaded {} total vector records", self.vector_state.records.len());
+ }
+ Err(e) => {
+ self.status_message = format!("Failed to load next page: {}", e);
+ }
+ }
+ }
+
+ pub async fn toggle_vector_records_mode(&mut self) {
+ self.showing_vector_records = !self.showing_vector_records;
+ if self.showing_vector_records && self.vector_state.records.is_empty() {
+ self.load_vector_records().await;
+ }
+ }
+
+ pub async fn load_vector_count(&mut self) {
+ self.status_message = "Loading vector count...".to_string();
+ match self.client.debug_vector_count(None).await {
+ Ok(count) => {
+ self.vector_state.total_count = Some(count);
+ self.status_message = format!("Total vector records: {}", count);
+ }
+ Err(e) => {
+ self.status_message = format!("Failed to load count: {}", e);
+ }
+ }
+ }
+
+ pub fn move_vector_cursor_up(&mut self) {
+ if self.vector_state.cursor > 0 {
+ self.vector_state.cursor -= 1;
+ }
+ }
+
+ pub fn move_vector_cursor_down(&mut self) {
+ if !self.vector_state.records.is_empty()
+ && self.vector_state.cursor < self.vector_state.records.len() - 1
+ {
+ self.vector_state.cursor += 1;
+ }
+ }
+
+ pub fn scroll_vector_top(&mut self) {
+ self.vector_state.cursor = 0;
+ }
+
+ pub fn scroll_vector_bottom(&mut self) {
+ if !self.vector_state.records.is_empty() {
+ self.vector_state.cursor = self.vector_state.records.len() - 1;
+ }
+ }
}
diff --git a/crates/ov_cli/src/tui/event.rs b/crates/ov_cli/src/tui/event.rs
index 4a382abcb..10a914ef2 100644
--- a/crates/ov_cli/src/tui/event.rs
+++ b/crates/ov_cli/src/tui/event.rs
@@ -10,6 +10,15 @@ pub async fn handle_key(app: &mut App, key: KeyEvent) {
KeyCode::Tab => {
app.toggle_focus();
}
+ KeyCode::Char('v') => {
+ app.toggle_vector_records_mode().await;
+ }
+ KeyCode::Char('n') if app.showing_vector_records => {
+ app.load_next_vector_page().await;
+ }
+ KeyCode::Char('c') if app.showing_vector_records => {
+ app.load_vector_count().await;
+ }
_ => match app.focus {
Panel::Tree => handle_tree_key(app, key).await,
Panel::Content => handle_content_key(app, key),
@@ -37,19 +46,37 @@ async fn handle_tree_key(app: &mut App, key: KeyEvent) {
}
fn handle_content_key(app: &mut App, key: KeyEvent) {
- match key.code {
- KeyCode::Char('j') | KeyCode::Down => {
- app.scroll_content_down();
+ if app.showing_vector_records {
+ match key.code {
+ KeyCode::Char('j') | KeyCode::Down => {
+ app.move_vector_cursor_down();
+ }
+ KeyCode::Char('k') | KeyCode::Up => {
+ app.move_vector_cursor_up();
+ }
+ KeyCode::Char('g') => {
+ app.scroll_vector_top();
+ }
+ KeyCode::Char('G') => {
+ app.scroll_vector_bottom();
+ }
+ _ => {}
}
- KeyCode::Char('k') | KeyCode::Up => {
- app.scroll_content_up();
- }
- KeyCode::Char('g') => {
- app.scroll_content_top();
+ } else {
+ match key.code {
+ KeyCode::Char('j') | KeyCode::Down => {
+ app.scroll_content_down();
+ }
+ KeyCode::Char('k') | KeyCode::Up => {
+ app.scroll_content_up();
+ }
+ KeyCode::Char('g') => {
+ app.scroll_content_top();
+ }
+ KeyCode::Char('G') => {
+ app.scroll_content_bottom();
+ }
+ _ => {}
}
- KeyCode::Char('G') => {
- app.scroll_content_bottom();
- }
- _ => {}
}
}
diff --git a/crates/ov_cli/src/tui/mod.rs b/crates/ov_cli/src/tui/mod.rs
index 0079a1122..6c9e9d28e 100644
--- a/crates/ov_cli/src/tui/mod.rs
+++ b/crates/ov_cli/src/tui/mod.rs
@@ -55,6 +55,10 @@ async fn run_loop(client: HttpClient, uri: &str) -> Result<()> {
area.height.saturating_sub(3) as usize
};
app.tree.adjust_scroll(tree_height);
+ // Adjust vector scroll before rendering
+ if app.showing_vector_records {
+ app.vector_state.adjust_scroll(tree_height);
+ }
terminal.draw(|frame| ui::render(frame, &app))?;
diff --git a/crates/ov_cli/src/tui/tree.rs b/crates/ov_cli/src/tui/tree.rs
index 076fdd08e..bc90a0a56 100644
--- a/crates/ov_cli/src/tui/tree.rs
+++ b/crates/ov_cli/src/tui/tree.rs
@@ -62,11 +62,25 @@ impl TreeState {
const ROOT_SCOPES: &'static [&'static str] = &["agent", "resources", "session", "user"];
pub async fn load_root(&mut self, client: &HttpClient, uri: &str) {
- let is_root = uri == "viking://" || uri == "viking:///";
+ let is_root = uri == "viking://" || uri == "viking:///" || uri == "/";
if is_root {
- // Synthesize root scope folders and eagerly load their children
- let mut root_nodes = Vec::new();
+ // Create a single "/" root directory node, which when expanded will show the scopes
+ let mut root_node = TreeNode {
+ entry: FsEntry {
+ uri: "/".to_string(),
+ size: None,
+ is_dir: true,
+ mod_time: None,
+ },
+ depth: 0,
+ expanded: true,
+ children_loaded: false,
+ children: Vec::new(),
+ };
+
+ // Preload the children (root scopes) so they're ready when expanding
+ let mut scope_nodes = Vec::new();
for scope in Self::ROOT_SCOPES {
let scope_uri = format!("viking://{}", scope);
let mut node = TreeNode {
@@ -76,28 +90,27 @@ impl TreeState {
is_dir: true,
mod_time: None,
},
- depth: 0,
+ depth: 1,
expanded: false,
children_loaded: false,
children: Vec::new(),
};
- // Try to load children eagerly to show first level
+ // Try to load children eagerly for scopes
if let Ok(mut children) = Self::fetch_children(client, &scope_uri).await {
for child in &mut children {
- child.depth = 1;
+ child.depth = 2;
}
node.children = children;
node.children_loaded = true;
- if !node.children.is_empty() {
- node.expanded = true;
- }
}
- // Always show all scopes
- root_nodes.push(node);
+ scope_nodes.push(node);
}
- self.nodes = root_nodes;
+ root_node.children = scope_nodes;
+ root_node.children_loaded = true;
+
+ self.nodes = vec![root_node];
self.rebuild_visible();
} else {
match Self::fetch_children(client, uri).await {
diff --git a/crates/ov_cli/src/tui/ui.rs b/crates/ov_cli/src/tui/ui.rs
index a67591acb..59c292e69 100644
--- a/crates/ov_cli/src/tui/ui.rs
+++ b/crates/ov_cli/src/tui/ui.rs
@@ -71,7 +71,9 @@ fn render_tree(frame: &mut Frame, app: &App, area: ratatui::layout::Rect) {
};
let style = if row.is_dir {
- Style::default().fg(Color::Blue).add_modifier(Modifier::BOLD)
+ Style::default()
+ .fg(Color::Blue)
+ .add_modifier(Modifier::BOLD)
} else {
Style::default()
};
@@ -91,7 +93,11 @@ fn render_tree(frame: &mut Frame, app: &App, area: ratatui::layout::Rect) {
let list = List::new(items).highlight_style(
Style::default()
- .bg(if focused { Color::DarkGray } else { Color::Reset })
+ .bg(if focused {
+ Color::DarkGray
+ } else {
+ Color::Reset
+ })
.fg(Color::White)
.add_modifier(Modifier::BOLD),
);
@@ -100,6 +106,11 @@ fn render_tree(frame: &mut Frame, app: &App, area: ratatui::layout::Rect) {
}
fn render_content(frame: &mut Frame, app: &App, area: ratatui::layout::Rect) {
+ if app.showing_vector_records {
+ render_vector_records(frame, app, area);
+ return;
+ }
+
let focused = app.focus == Panel::Content;
let border_color = if focused {
Color::Cyan
@@ -126,20 +137,193 @@ fn render_content(frame: &mut Frame, app: &App, area: ratatui::layout::Rect) {
frame.render_widget(paragraph, area);
}
-fn render_status_bar(frame: &mut Frame, _app: &App, area: ratatui::layout::Rect) {
- let hints = Line::from(vec![
- Span::styled(" q", Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)),
+fn render_vector_records(frame: &mut Frame, app: &App, area: ratatui::layout::Rect) {
+ let focused = app.focus == Panel::Content;
+ let border_color = if focused {
+ Color::Cyan
+ } else {
+ Color::DarkGray
+ };
+
+ let title = if let Some(total) = app.vector_state.total_count {
+ format!(
+ " Vector Records ({}/{}, total: {}) ",
+ app.vector_state.cursor + 1,
+ app.vector_state.records.len(),
+ total
+ )
+ } else {
+ format!(
+ " Vector Records ({}/{}) ",
+ app.vector_state.cursor + 1,
+ app.vector_state.records.len()
+ )
+ };
+
+ let block = Block::default()
+ .title(title)
+ .borders(Borders::ALL)
+ .border_style(Style::default().fg(border_color));
+
+ let inner = block.inner(area);
+ frame.render_widget(block, area);
+
+ if app.vector_state.records.is_empty() {
+ let empty =
+ Paragraph::new("(no vector records)").style(Style::default().fg(Color::DarkGray));
+ frame.render_widget(empty, inner);
+ return;
+ }
+
+ let viewport_height = inner.height as usize;
+
+ let items: Vec<ListItem> = app
+ .vector_state
+ .records
+ .iter()
+ .skip(app.vector_state.scroll_offset)
+ .take(viewport_height)
+ .map(|record| {
+ let id = record
+ .get("id")
+ .and_then(|v| v.as_str())
+ .unwrap_or("(no id)");
+ let uri = record
+ .get("uri")
+ .and_then(|v| v.as_str())
+ .unwrap_or("(no uri)");
+ let line = Line::from(vec![
+ Span::styled(
+ id,
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(" "),
+ Span::raw(uri),
+ ]);
+ ListItem::new(line)
+ })
+ .collect();
+
+ let adjusted_cursor = app
+ .vector_state
+ .cursor
+ .saturating_sub(app.vector_state.scroll_offset);
+ let mut list_state = ListState::default().with_selected(Some(adjusted_cursor));
+
+ let list = List::new(items).highlight_style(
+ Style::default()
+ .bg(if focused {
+ Color::DarkGray
+ } else {
+ Color::Reset
+ })
+ .fg(Color::White)
+ .add_modifier(Modifier::BOLD),
+ );
+
+ frame.render_stateful_widget(list, inner, &mut list_state);
+}
+
+fn render_status_bar(frame: &mut Frame, app: &App, area: ratatui::layout::Rect) {
+ let mut hints = vec![
+ Span::styled(
+ " q",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
Span::raw(":quit "),
- Span::styled("TAB", Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)),
+ Span::styled(
+ "TAB",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
Span::raw(":switch "),
- Span::styled("j/k", Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)),
- Span::raw(":navigate "),
- Span::styled(".", Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)),
- Span::raw(":toggle folder "),
- Span::styled("g/G", Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)),
- Span::raw(":top/bottom"),
- ]);
-
- let bar = Paragraph::new(hints).style(Style::default().bg(Color::DarkGray).fg(Color::White));
+ ];
+
+ if app.showing_vector_records {
+ hints.extend_from_slice(&[
+ Span::styled(
+ "v",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":files "),
+ Span::styled(
+ "j/k",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":navigate "),
+ Span::styled(
+ "n",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":next page "),
+ Span::styled(
+ "c",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":count "),
+ Span::styled(
+ "g/G",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":top/bottom"),
+ ]);
+ } else {
+ hints.extend_from_slice(&[
+ Span::styled(
+ "v",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":vectors "),
+ Span::styled(
+ "j/k",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":navigate "),
+ Span::styled(
+ ".",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":toggle folder "),
+ Span::styled(
+ "g/G",
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ ),
+ Span::raw(":top/bottom"),
+ ]);
+ }
+
+ if !app.status_message.is_empty() {
+ hints.push(Span::raw(" | "));
+ hints.push(Span::styled(
+ &app.status_message,
+ Style::default().fg(Color::Cyan),
+ ));
+ }
+
+ let bar = Paragraph::new(Line::from(hints))
+ .style(Style::default().bg(Color::DarkGray).fg(Color::White));
frame.render_widget(bar, area);
}
diff --git a/openviking/server/routers/debug.py b/openviking/server/routers/debug.py
index f2c04756d..5cc5f6a74 100644
--- a/openviking/server/routers/debug.py
+++ b/openviking/server/routers/debug.py
@@ -4,14 +4,19 @@
Provides debug API for system diagnostics.
- /api/v1/debug/health - Quick health check
+- /api/v1/debug/vector/scroll - Paginated vector records
+- /api/v1/debug/vector/count - Count vector records
"""
-from fastapi import APIRouter, Depends
+from typing import Optional
+
+from fastapi import APIRouter, Depends, Query
from openviking.server.auth import get_request_context
from openviking.server.dependencies import get_service
from openviking.server.identity import RequestContext
-from openviking.server.models import Response
+from openviking.server.models import ErrorInfo, Response
+from openviking.storage import VikingDBManagerProxy
router = APIRouter(prefix="/api/v1/debug", tags=["debug"])
@@ -24,3 +29,54 @@ async def debug_health(
service = get_service()
is_healthy = service.debug.is_healthy()
return Response(status="ok", result={"healthy": is_healthy})
+
+
[email protected]("/vector/scroll")
+async def debug_vector_scroll(
+ limit: int = Query(100, ge=1, le=1000),
+ cursor: Optional[str] = None,
+ _ctx: RequestContext = Depends(get_request_context),
+):
+ """Get paginated vector records with tenant isolation."""
+ service = get_service()
+ if not service.vikingdb_manager:
+ return Response(
+ status="error",
+ error=ErrorInfo(code="NO_VECTOR_DB", message="Vector DB not initialized"),
+ )
+
+ proxy = VikingDBManagerProxy(service.vikingdb_manager, _ctx)
+ records, next_cursor = await proxy.scroll(limit=limit, cursor=cursor)
+
+ return Response(status="ok", result={"records": records, "next_cursor": next_cursor})
+
+
[email protected]("/vector/count")
+async def debug_vector_count(
+ filter: Optional[str] = None,
+ _ctx: RequestContext = Depends(get_request_context),
+):
+ """Get count of vector records with tenant isolation."""
+ import json
+
+ service = get_service()
+ if not service.vikingdb_manager:
+ return Response(
+ status="error",
+ error=ErrorInfo(code="NO_VECTOR_DB", message="Vector DB not initialized"),
+ )
+
+ proxy = VikingDBManagerProxy(service.vikingdb_manager, _ctx)
+
+ filter_expr = None
+ if filter:
+ try:
+ filter_expr = json.loads(filter)
+ except json.JSONDecodeError:
+ return Response(
+ status="error",
+ error=ErrorInfo(code="INVALID_FILTER", message="Invalid filter JSON"),
+ )
+
+ count = await proxy.count(filter=filter_expr)
+ return Response(status="ok", result={"count": count})