pub struct GraphRAGService<G: GraphBackend> {
recall: Arc<RecallService>,
graph: Arc<GraphService<G>>,
extractor: EntityExtractorService,
config: GraphRAGConfig,
}Expand description
Service for hybrid search combining semantic search with graph expansion.
The Graph RAG service enhances traditional memory recall by:
- Extracting entities from the user’s query
- Expanding the knowledge graph to find related entities
- Retrieving memories linked to those entities
- Merging and re-ranking results from both sources
This provides contextually richer results that leverage the connections between concepts, people, and technologies in the knowledge graph.
Fields§
§recall: Arc<RecallService>The recall service for semantic/text search.
graph: Arc<GraphService<G>>The graph service for knowledge graph operations.
extractor: EntityExtractorServiceThe entity extractor for query analysis.
config: GraphRAGConfigConfiguration for the service.
Implementations§
Source§impl<G: GraphBackend> GraphRAGService<G>
impl<G: GraphBackend> GraphRAGService<G>
Sourcepub const fn new(
recall: Arc<RecallService>,
graph: Arc<GraphService<G>>,
extractor: EntityExtractorService,
config: GraphRAGConfig,
) -> Self
pub const fn new( recall: Arc<RecallService>, graph: Arc<GraphService<G>>, extractor: EntityExtractorService, config: GraphRAGConfig, ) -> Self
Creates a new Graph RAG service.
§Arguments
recall- The recall service for semantic search.graph- The graph service for knowledge graph operations.extractor- The entity extractor for query analysis.config- Configuration for the service.
Sourcepub fn search_with_expansion(
&self,
query: &str,
filter: &SearchFilter,
limit: usize,
expansion: Option<ExpansionConfig>,
) -> Result<GraphSearchResults>
pub fn search_with_expansion( &self, query: &str, filter: &SearchFilter, limit: usize, expansion: Option<ExpansionConfig>, ) -> Result<GraphSearchResults>
Performs a hybrid search with graph expansion.
This method:
- Runs traditional semantic/text search via
RecallService - Extracts entities from the query
- Traverses the knowledge graph to find related entities
- Retrieves memories linked to those entities
- Merges and re-ranks all results
§Arguments
query- The search query.filter- Search filter to apply.limit- Maximum number of results to return.expansion- Optional expansion configuration.
§Returns
A GraphSearchResults containing all matched memories with provenance.
§Errors
Returns an error if search or graph operations fail.
Sourcefn expand_from_entities(
&self,
entity_names: &[String],
expansion: &ExpansionConfig,
) -> Result<HashMap<MemoryId, (f32, EntityId, usize)>>
fn expand_from_entities( &self, entity_names: &[String], expansion: &ExpansionConfig, ) -> Result<HashMap<MemoryId, (f32, EntityId, usize)>>
Expands the graph from extracted entity names.
Sourcefn expand_single_entity(
&self,
entity: &Entity,
depth: usize,
expansion: &ExpansionConfig,
results: &mut HashMap<MemoryId, (f32, EntityId, usize)>,
) -> Result<()>
fn expand_single_entity( &self, entity: &Entity, depth: usize, expansion: &ExpansionConfig, results: &mut HashMap<MemoryId, (f32, EntityId, usize)>, ) -> Result<()>
Expands a single entity and collects memory links.
Sourcefn score_and_insert_memories(
&self,
memory_ids: &[MemoryId],
source_entity: &EntityId,
hop_count: usize,
use_weight: bool,
results: &mut HashMap<MemoryId, (f32, EntityId, usize)>,
)
fn score_and_insert_memories( &self, memory_ids: &[MemoryId], source_entity: &EntityId, hop_count: usize, use_weight: bool, results: &mut HashMap<MemoryId, (f32, EntityId, usize)>, )
Calculates scores and inserts memory links into results.
Sourcefn update_or_insert_memory(
results: &mut HashMap<MemoryId, (f32, EntityId, usize)>,
memory_id: &MemoryId,
score: f32,
source_entity: &EntityId,
hop_count: usize,
)
fn update_or_insert_memory( results: &mut HashMap<MemoryId, (f32, EntityId, usize)>, memory_id: &MemoryId, score: f32, source_entity: &EntityId, hop_count: usize, )
Updates an existing memory entry or inserts a new one.
Sourcefn find_entities_by_name(&self, name: &str) -> Result<Vec<Entity>>
fn find_entities_by_name(&self, name: &str) -> Result<Vec<Entity>>
Finds entities by name (case-insensitive search).
Sourcefn traverse_entity(
&self,
entity_id: &EntityId,
max_depth: usize,
) -> Result<Vec<(EntityId, usize)>>
fn traverse_entity( &self, entity_id: &EntityId, max_depth: usize, ) -> Result<Vec<(EntityId, usize)>>
Traverses the graph from an entity up to the specified depth.
Sourcefn add_neighbors_to_frontier(
&self,
entity_id: &EntityId,
current_depth: usize,
frontier: &mut Vec<(EntityId, usize)>,
) -> Result<()>
fn add_neighbors_to_frontier( &self, entity_id: &EntityId, current_depth: usize, frontier: &mut Vec<(EntityId, usize)>, ) -> Result<()>
Adds neighbors of an entity to the traversal frontier.
Sourcefn get_entity_memory_links(&self, entity_id: &EntityId) -> Result<Vec<MemoryId>>
fn get_entity_memory_links(&self, entity_id: &EntityId) -> Result<Vec<MemoryId>>
Gets memory IDs linked to an entity via mentions.
Sourcefn merge_results(
&self,
semantic: SearchResult,
graph: HashMap<MemoryId, (f32, EntityId, usize)>,
_expansion: &ExpansionConfig,
) -> Result<Vec<GraphSearchHit>>
fn merge_results( &self, semantic: SearchResult, graph: HashMap<MemoryId, (f32, EntityId, usize)>, _expansion: &ExpansionConfig, ) -> Result<Vec<GraphSearchHit>>
Merges semantic results with graph expansion results.
Sourcefn merge_single_graph_result(
&self,
hits: &mut HashMap<String, GraphSearchHit>,
id: String,
memory_id: &MemoryId,
graph_score: f32,
source_entity: EntityId,
hop_count: usize,
)
fn merge_single_graph_result( &self, hits: &mut HashMap<String, GraphSearchHit>, id: String, memory_id: &MemoryId, graph_score: f32, source_entity: EntityId, hop_count: usize, )
Merges a single graph result into the hits map.
Sourcepub fn search_semantic_only(
&self,
query: &str,
filter: &SearchFilter,
limit: usize,
) -> Result<GraphSearchResults>
pub fn search_semantic_only( &self, query: &str, filter: &SearchFilter, limit: usize, ) -> Result<GraphSearchResults>
Performs semantic-only search (no graph expansion).
This is useful for comparison or when graph expansion is not desired.
§Errors
Returns an error if the semantic search operation fails.
Sourcepub fn search_graph_only(
&self,
query: &str,
limit: usize,
expansion: Option<ExpansionConfig>,
) -> Result<GraphSearchResults>
pub fn search_graph_only( &self, query: &str, limit: usize, expansion: Option<ExpansionConfig>, ) -> Result<GraphSearchResults>
Performs graph-only search (no semantic search).
Searches by extracting entities from the query and expanding the graph.
§Errors
Returns an error if entity extraction or graph expansion fails.
Auto Trait Implementations§
impl<G> Freeze for GraphRAGService<G>
impl<G> !RefUnwindSafe for GraphRAGService<G>
impl<G> Send for GraphRAGService<G>
impl<G> Sync for GraphRAGService<G>
impl<G> Unpin for GraphRAGService<G>
impl<G> !UnwindSafe for GraphRAGService<G>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].