-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add crawl_and_index example (#2105)
* add cmt * update * renamings * add crawl_and_index example * update * update * update
- Loading branch information
Showing
11 changed files
with
78 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::sync::Arc; | ||
|
||
use async_stream::stream; | ||
use async_trait::async_trait; | ||
use futures::StreamExt; | ||
use tabby_inference::Embedding; | ||
use tabby_scheduler::{crawl::crawl_pipeline, DocIndex, SourceDocument}; | ||
use tracing::debug; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
tracing_subscriber::fmt() | ||
.with_env_filter("tabby=debug,crawl_and_index=debug") | ||
.init(); | ||
|
||
let mut doc_index = DocIndex::new(Arc::new(FakeEmbedding)); | ||
let mut cnt = 0; | ||
stream! { | ||
for await doc in crawl_pipeline("https://tabby.tabbyml.com/").await { | ||
debug!("Title: {:?}", doc.metadata.title); | ||
debug!("Description: {:?}", doc.metadata.description); | ||
debug!("URL: {}\n", doc.url); | ||
cnt += 1; | ||
if cnt >= 3 { | ||
break; | ||
} | ||
|
||
let id = cnt.to_string(); | ||
debug!("Adding document {} to index...", id); | ||
let source_doc = SourceDocument { | ||
id, | ||
title: doc.metadata.title.unwrap_or_default(), | ||
link: doc.url, | ||
body: doc.markdown, | ||
}; | ||
|
||
doc_index.add(source_doc).await; | ||
} | ||
|
||
doc_index.commit(); | ||
} | ||
.collect::<()>() | ||
.await; | ||
} | ||
|
||
struct FakeEmbedding; | ||
|
||
#[async_trait] | ||
impl Embedding for FakeEmbedding { | ||
async fn embed(&self, _: &str) -> anyhow::Result<Vec<f32>> { | ||
let mut embedding = vec![0.0; 512]; | ||
embedding[3] = 1.0; | ||
embedding[128] = 1.0; | ||
Ok(embedding) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters