Skip to content

Commit

Permalink
Bump up to version 1.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dialogflowchatbot committed Aug 8, 2024
1 parent 04052d9 commit 2bf7878
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 426 deletions.
10 changes: 5 additions & 5 deletions src/ai/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ async fn ollama(
}
}
}
log::info!(
"Ollama embedding result {:?} {:?}",
embedding_result.get(0),
embedding_result.get(1)
);
// log::info!(
// "Ollama embedding result {:?} {:?}",
// embedding_result.get(0),
// embedding_result.get(1)
// );
Ok(embedding_result)
}
9 changes: 6 additions & 3 deletions src/db/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ fn get_idx_db() -> Result<Database> {

async fn create_idx_db(robot_id: &str) -> Result<()> {
let config = SourceConfig::new(robot_id, "id", "vectors").with_metadata(vec!["intent_id"]);
let params = ParamsIVFPQ::default();
let algorithm = IndexAlgorithm::IVFPQ(params);
// let params = ParamsIVFPQ::default();
// let algorithm = IndexAlgorithm::IVFPQ(params);
let mut params = ParamsFlat::default();
params.metric = oasysdb::types::distance::DistanceMetric::Cosine;
let algorithm = IndexAlgorithm::Flat(params);
get_idx_db()?
.async_create_index(robot_id, algorithm, config)
.await?;
Expand Down Expand Up @@ -104,7 +107,7 @@ pub(crate) async fn init_datasource() -> Result<()> {
.acquire_timeout(Duration::from_secs(5))
.test_before_acquire(true);
let conn_str = get_sqlite_url()?;
log::info!("Embedding database path: {}", &conn_str);
// log::info!("Embedding database path: {}", &conn_str);
let pool = pool_ops.connect(conn_str.as_str()).await?;
DATA_SOURCE
.set(pool)
Expand Down
8 changes: 5 additions & 3 deletions src/intent/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ use crate::result::{Error, Result};
pub(crate) async fn detect(robot_id: &str, s: &str) -> Result<Option<String>> {
// let now = std::time::Instant::now();
let embedding = embedding(robot_id, s).await?;
// log::info!("Generate embedding cost {:?}", now.elapsed());
// let s = format!("{:?}", &embedding);
// let regex = regex::Regex::new(r"\s").unwrap();
// log::info!("detect embedding {}", regex.replace_all(&s, ""));
// let now = std::time::Instant::now();
let search_vector: Vec<f32> = embedding.0.into();
let similarity_threshold = embedding.1;
let result = embedding_db::search_idx_db(robot_id, search_vector.into())?;
// println!("inner intent detect {:?}", now.elapsed());
if result.len() == 0 {
// log::info!("Searching vector took {:?}", now.elapsed());
if !result.is_empty() {
if let Some(record) = result.get(0) {
log::info!("Record distance: {}", record.distance);
if similarity_threshold >= record.distance {
if (1f32 - record.distance) >= similarity_threshold {
if let Some(data) = record.data.get("intent_id") {
if let Some(metadata) = data {
if let oasysdb::types::record::DataValue::String(s) = metadata {
Expand Down
1 change: 1 addition & 0 deletions src/resources/assets/assets/index-BjYMHWgz.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/resources/assets/assets/index-CFMBpwmb.css

This file was deleted.

414 changes: 0 additions & 414 deletions src/resources/assets/assets/index-CGwDfCl8.js

This file was deleted.

414 changes: 414 additions & 0 deletions src/resources/assets/assets/index-CQUEiyGj.js

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2bf7878

Please sign in to comment.