feat: rag-embedding-ai-chat (#1)
Co-authored-by: Sharang Parnerkar <parnerkarsharang@gmail.com> Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -52,7 +52,7 @@ pub async fn get_graph(
|
||||
// so there is only one set of nodes/edges per repo.
|
||||
let filter = doc! { "repo_id": &repo_id };
|
||||
|
||||
let nodes: Vec<CodeNode> = match db.graph_nodes().find(filter.clone()).await {
|
||||
let all_nodes: Vec<CodeNode> = match db.graph_nodes().find(filter.clone()).await {
|
||||
Ok(cursor) => collect_cursor_async(cursor).await,
|
||||
Err(_) => Vec::new(),
|
||||
};
|
||||
@@ -60,6 +60,17 @@ pub async fn get_graph(
|
||||
Ok(cursor) => collect_cursor_async(cursor).await,
|
||||
Err(_) => Vec::new(),
|
||||
};
|
||||
|
||||
// Remove disconnected nodes (no edges) to keep the graph clean
|
||||
let connected: std::collections::HashSet<&str> = edges
|
||||
.iter()
|
||||
.flat_map(|e| [e.source.as_str(), e.target.as_str()])
|
||||
.collect();
|
||||
let nodes = all_nodes
|
||||
.into_iter()
|
||||
.filter(|n| connected.contains(n.qualified_name.as_str()))
|
||||
.collect();
|
||||
|
||||
(nodes, edges)
|
||||
} else {
|
||||
(Vec::new(), Vec::new())
|
||||
@@ -235,12 +246,7 @@ pub async fn get_file_content(
|
||||
// Cap at 10,000 lines
|
||||
let truncated: String = content.lines().take(10_000).collect::<Vec<_>>().join("\n");
|
||||
|
||||
let language = params
|
||||
.path
|
||||
.rsplit('.')
|
||||
.next()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let language = params.path.rsplit('.').next().unwrap_or("").to_string();
|
||||
|
||||
Ok(Json(ApiResponse {
|
||||
data: FileContent {
|
||||
|
||||
Reference in New Issue
Block a user