diff --git a/Cargo.lock b/Cargo.lock index a2e3e1a465..b7c3b92754 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8617,6 +8617,7 @@ dependencies = [ "anyhow", "async-trait", "client", + "clock", "collections", "env_logger", "fs", diff --git a/crates/semantic_index/Cargo.toml b/crates/semantic_index/Cargo.toml index 118046bddd..946c75870b 100644 --- a/crates/semantic_index/Cargo.toml +++ b/crates/semantic_index/Cargo.toml @@ -12,6 +12,7 @@ path = "src/semantic_index.rs" anyhow.workspace = true async-trait.workspace = true client.workspace = true +clock.workspace = true collections.workspace = true fs.workspace = true futures.workspace = true diff --git a/crates/semantic_index/examples/index.rs b/crates/semantic_index/examples/index.rs index 846f93b5fc..889dcba9d7 100644 --- a/crates/semantic_index/examples/index.rs +++ b/crates/semantic_index/examples/index.rs @@ -1,11 +1,13 @@ +use client::Client; use futures::channel::oneshot; use gpui::{App, Global, TestAppContext}; use language::language_settings::AllLanguageSettings; use project::Project; use semantic_index::SemanticIndex; use settings::SettingsStore; -use std::path::Path; +use std::{path::Path, sync::Arc}; use tempfile::tempdir; +use util::http::HttpClientWithUrl; pub fn init_test(cx: &mut TestAppContext) { _ = cx.update(|cx| { @@ -22,6 +24,8 @@ pub fn init_test(cx: &mut TestAppContext) { fn main() { env_logger::init(); + use clock::FakeSystemClock; + App::new().run(|cx| { let store = SettingsStore::test(cx); cx.set_global(store); @@ -31,6 +35,12 @@ fn main() { store.update_user_settings::(cx, |_| {}); }); + let clock = Arc::new(FakeSystemClock::default()); + let http = Arc::new(HttpClientWithUrl::new("http://localhost:11434")); + + let client = client::Client::new(clock, http.clone(), cx); + Client::set_global(client.clone(), cx); + let temp_dir = tempdir().unwrap(); let semantic_index = SemanticIndex::new(temp_dir.path(), cx); diff --git a/crates/semantic_index/src/chunking.rs b/crates/semantic_index/src/chunking.rs index a6b0d5b0cb..591b3cef6a 100644 --- a/crates/semantic_index/src/chunking.rs +++ b/crates/semantic_index/src/chunking.rs @@ -4,6 +4,7 @@ use std::{cmp, ops::Range, sync::Arc}; const CHUNK_THRESHOLD: usize = 1500; +#[derive(Debug, Clone)] pub struct Chunk { pub range: Range, digest: [u8; 32], diff --git a/crates/semantic_index/src/embedding.rs b/crates/semantic_index/src/embedding.rs index f103782afc..ea9e823337 100644 --- a/crates/semantic_index/src/embedding.rs +++ b/crates/semantic_index/src/embedding.rs @@ -14,6 +14,7 @@ pub const EMBEDDING_SIZE_LARGE: usize = 3072; // TODO: Check out Voyage +#[derive(Debug, Clone)] pub enum Embedding { Tiny([f32; EMBEDDING_SIZE_TINY]), Small([f32; EMBEDDING_SIZE_SMALL]), diff --git a/crates/semantic_index/src/semantic_index.rs b/crates/semantic_index/src/semantic_index.rs index 3c73891402..4eb6eca9cd 100644 --- a/crates/semantic_index/src/semantic_index.rs +++ b/crates/semantic_index/src/semantic_index.rs @@ -357,7 +357,7 @@ impl WorktreeIndex { .into_iter() .filter_map(|(chunk, embedding)| { embedding - .ok() + .log_err() .map(|embedding| EmbeddedChunk { chunk, embedding }) }) .collect::>(); @@ -382,7 +382,12 @@ impl WorktreeIndex { embedded_files: channel::Receiver, cx: &mut AsyncAppContext, ) -> Task<()> { - todo!() + // Let's just log the files for now + cx.spawn(|cx| async move { + while let Ok(embedded_file) = embedded_files.recv().await { + // println!("Embedded file: {:?}", embedded_file.chunks); + } + }) } } @@ -399,6 +404,7 @@ struct EmbeddedFile { chunks: Vec, } +#[derive(Debug)] struct EmbeddedChunk { chunk: Chunk, embedding: Embedding,