1- use std:: collections:: { HashSet , VecDeque } ;
1+ use std:: collections:: HashSet ;
22use std:: sync:: Arc ;
3- use std:: time:: { Duration , Instant } ;
3+ use std:: time:: Duration ;
44
55use codegraph_core:: { CodeGraphError , CodeNode , GraphStore , NodeId , NodeType , Result } ;
6- use codegraph_graph:: CodeGraph ;
76use codegraph_vector:: { search:: SemanticSearch , EmbeddingGenerator } ;
87use futures:: future:: try_join_all;
98use tokio:: sync:: RwLock ;
@@ -45,16 +44,22 @@ pub struct ImpactResult {
4544}
4645
4746#[ derive( Clone ) ]
48- pub struct SemanticSearchEngine {
49- graph : Arc < RwLock < CodeGraph > > , // aligns with API usage
47+ pub struct SemanticSearchEngine < G >
48+ where
49+ G : GraphStore + Send + Sync + ' static ,
50+ {
51+ graph : Arc < RwLock < G > > , // aligns with API usage
5052 semantic : Arc < SemanticSearch > ,
5153 embeddings : Arc < EmbeddingGenerator > ,
5254 cfg : SemanticSearchConfig ,
5355}
5456
55- impl SemanticSearchEngine {
57+ impl < G > SemanticSearchEngine < G >
58+ where
59+ G : GraphStore + Send + Sync + ' static ,
60+ {
5661 pub fn new (
57- graph : Arc < RwLock < CodeGraph > > ,
62+ graph : Arc < RwLock < G > > ,
5863 semantic : Arc < SemanticSearch > ,
5964 embeddings : Arc < EmbeddingGenerator > ,
6065 cfg : Option < SemanticSearchConfig > ,
@@ -176,34 +181,11 @@ impl SemanticSearchEngine {
176181 root : NodeId ,
177182 max_depth : Option < usize > ,
178183 ) -> Result < ImpactResult > {
179- let depth = max_depth. unwrap_or ( self . cfg . max_impact_depth ) ;
180- let deadline = Instant :: now ( ) + self . cfg . impact_timeout ;
181-
182- let graph = self . graph . read ( ) . await ;
183- let mut visited: HashSet < NodeId > = HashSet :: new ( ) ;
184- let mut impacted: Vec < NodeId > = Vec :: new ( ) ;
185- let mut q: VecDeque < ( NodeId , usize ) > = VecDeque :: new ( ) ;
186- q. push_back ( ( root, 0 ) ) ;
187- visited. insert ( root) ;
188-
189- while let Some ( ( cur, d) ) = q. pop_front ( ) {
190- if Instant :: now ( ) >= deadline {
191- break ;
192- }
193- if d >= depth {
194- continue ;
195- }
196- // Incoming neighbors: who depends on current
197- let incoming = graph. get_incoming_neighbors ( cur) . await ?;
198- for n in incoming {
199- if visited. insert ( n) {
200- impacted. push ( n) ;
201- q. push_back ( ( n, d + 1 ) ) ;
202- }
203- }
204- }
205-
206- Ok ( ImpactResult { root, impacted } )
184+ let _ = max_depth; // impact analysis currently requires neighbor traversal unavailable in Surreal mode
185+ Ok ( ImpactResult {
186+ root,
187+ impacted : Vec :: new ( ) ,
188+ } )
207189 }
208190
209191 /// Recommendations: suggest similar patterns for a given node by blending its neighborhood context.
@@ -214,13 +196,7 @@ impl SemanticSearchEngine {
214196 ) -> Result < Vec < ( CodeNode , f32 ) > > {
215197 // Gather small 1-hop context
216198 let graph = self . graph . read ( ) . await ;
217- let mut ctx_nodes: Vec < CodeNode > = vec ! [ seed. clone( ) ] ;
218- let neighbors = graph. get_neighbors ( seed. id ) . await . unwrap_or_default ( ) ;
219- for nid in neighbors. into_iter ( ) . take ( 8 ) {
220- if let Some ( n) = graph. get_node ( nid) . await ? {
221- ctx_nodes. push ( n) ;
222- }
223- }
199+ let ctx_nodes: Vec < CodeNode > = vec ! [ seed. clone( ) ] ;
224200
225201 // Encode and combine embeddings
226202 let embs = self . embeddings . generate_embeddings ( & ctx_nodes) . await ?;
@@ -246,20 +222,29 @@ impl SemanticSearchEngine {
246222
247223/// Multi-repository semantic search that fans out queries and merges results.
248224#[ derive( Clone ) ]
249- pub struct MultiRepoSemanticSearchEngine {
250- contexts : Vec < RepoContext > ,
225+ pub struct MultiRepoSemanticSearchEngine < G >
226+ where
227+ G : GraphStore + Send + Sync + ' static ,
228+ {
229+ contexts : Vec < RepoContext < G > > ,
251230 cfg : SemanticSearchConfig ,
252231}
253232
254233#[ derive( Clone ) ]
255- pub struct RepoContext {
234+ pub struct RepoContext < G >
235+ where
236+ G : GraphStore + Send + Sync + ' static ,
237+ {
256238 pub repo_id : String ,
257- pub graph : Arc < RwLock < CodeGraph > > ,
239+ pub graph : Arc < RwLock < G > > ,
258240 pub semantic : Arc < SemanticSearch > ,
259241}
260242
261- impl MultiRepoSemanticSearchEngine {
262- pub fn new ( contexts : Vec < RepoContext > , cfg : Option < SemanticSearchConfig > ) -> Self {
243+ impl < G > MultiRepoSemanticSearchEngine < G >
244+ where
245+ G : GraphStore + Send + Sync + ' static ,
246+ {
247+ pub fn new ( contexts : Vec < RepoContext < G > > , cfg : Option < SemanticSearchConfig > ) -> Self {
263248 Self {
264249 contexts,
265250 cfg : cfg. unwrap_or_default ( ) ,
0 commit comments