Embed a query and search for the most similar memories within a scope.
(
&self,
query: &str,
scope: &MemoryScope,
top_k: usize,
)
| 119 | |
| 120 | /// Embed a query and search for the most similar memories within a scope. |
| 121 | pub async fn search( |
| 122 | &self, |
| 123 | query: &str, |
| 124 | scope: &MemoryScope, |
| 125 | top_k: usize, |
| 126 | ) -> GraphBitResult<Vec<ScoredMemory>> { |
| 127 | let query_embedding = self.embedding_service.embed_text(query).await?; |
| 128 | let results = self |
| 129 | .vector_index |
| 130 | .search(&query_embedding, top_k, self.config.similarity_threshold) |
| 131 | .await?; |
| 132 | |
| 133 | let mut scored = Vec::new(); |
| 134 | for (memory_id, score) in results { |
| 135 | if let Some(memory) = self.store.get_memory(&memory_id).await? { |
| 136 | if matches_scope(&memory.scope, scope) { |
| 137 | scored.push(ScoredMemory { memory, score }); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | Ok(scored) |
| 143 | } |
| 144 | |
| 145 | /// Get a single memory by its ID. |
| 146 | pub async fn get(&self, memory_id: &MemoryId) -> GraphBitResult<Option<Memory>> { |
nothing calls this directly
no test coverage detected