Skip to content

Commit

Permalink
made a few things a bit more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Oct 8, 2024
1 parent 3698043 commit 0b222d2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ MEILI_MASTER_KEY=CHANGE_ME

# general
# LOG_LEVEL = debug # can be uaed to overide the log level

MEILI_OLLAMA_URL=http://131.159.2.46:11434/api/embeddings
MEILI_HYBRID_RATIO=0.1
2 changes: 2 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ services:
CONNECTUM_OAUTH_CLIENT_SECRET: ${CONNECTUM_OAUTH_CLIENT_SECRET}
GITHUB_TOKEN: ${GITHUB_TOKEN}
JWT_KEY: ${JWT_KEY}
MEILI_OLLAMA_URL: ${MEILI_OLLAMA_URL}
MEILI_HYBRID_RATIO: ${MEILI_HYBRID_RATIO}
depends_on:
meilisearch:
condition: service_healthy
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ services:
CONNECTUM_OAUTH_CLIENT_SECRET: ${CONNECTUM_OAUTH_CLIENT_SECRET}
GITHUB_TOKEN: ${GITHUB_TOKEN}
JWT_KEY: ${JWT_KEY}
MEILI_OLLAMA_URL: ${MEILI_OLLAMA_URL}
MEILI_HYBRID_RATIO: ${MEILI_HYBRID_RATIO}
depends_on:
meilisearch:
condition: service_healthy
Expand Down
6 changes: 2 additions & 4 deletions server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ chrono = { version = "0.4.38", default-features = false, features = ["serde"] }

# search
# IFF (open for 4 Months now) meilisearch merges my PR, change back to the main release
meilisearch = { git = "https://github.com/commanderstorm/meilisearch-rust.git", branch = "vector-search-embedder" }
meilisearch-sdk = { git = "https://github.com/commanderstorm/meilisearch-rust.git", branch = "vector-search-embedder" }
logos = "0.14.1"
regex = "1.10.6"

Expand Down
26 changes: 21 additions & 5 deletions server/src/search/search_executor/query.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::search::search_executor::parser::{Filter, ParsedQuery, TextToken};
use crate::search::{Highlighting, Limits};
use actix_web::dev::ResourcePath;
use meilisearch_sdk::client::Client;
use meilisearch_sdk::errors::Error;
use meilisearch_sdk::indexes::Index;
use meilisearch_sdk::search::{MultiSearchResponse, SearchQuery, Selectors};
use serde::Deserialize;
use std::fmt::{Debug, Formatter};

use crate::search::search_executor::parser::{Filter, ParsedQuery, TextToken};
use crate::search::{Highlighting, Limits};

#[derive(Deserialize, Default, Clone)]
#[allow(dead_code)]
pub(super) struct MSHit {
Expand Down Expand Up @@ -178,12 +178,20 @@ impl GeoEntryQuery {
&'b self,
entries: &'a Index,
) -> SearchQuery<'a, meilisearch_sdk::DefaultHttpClient> {
let semantic_ratio = match std::env::var("MEILI_HYBRID_RATIO").ok() {
None => None,
Some(s) if s.trim().is_empty() => None,
Some(s) => Some(s),
}
.unwrap_or("0.1".into())
.parse()
.unwrap_or(0.1);
SearchQuery::new(entries)
.with_facets(Selectors::Some(&["facet"]))
.with_highlight_pre_tag(&self.highlighting.pre)
.with_highlight_post_tag(&self.highlighting.post)
.with_attributes_to_highlight(Selectors::Some(&["name"]))
.with_hybrid("default", 0.1)
.with_hybrid("default", semantic_ratio)
.build()
}

Expand All @@ -208,11 +216,19 @@ impl GeoEntryQuery {
entries: &'a Index,
query: &'a str,
) -> SearchQuery<'a, meilisearch_sdk::DefaultHttpClient> {
let semantic_ratio = match std::env::var("MEILI_HYBRID_RATIO").ok() {
None => None,
Some(s) if s.trim().is_empty() => None,
Some(s) => Some(s),
}
.unwrap_or("0.1".into())
.parse()
.unwrap_or(0.1);
self.common_query(entries)
.with_query(query)
.with_limit(2 * self.limits.buildings_count) // we might do reordering later
.with_filter(&self.filters.buildings)
.with_hybrid("default", 0.1)
.with_hybrid("default", semantic_ratio)
.build()
}

Expand Down
14 changes: 5 additions & 9 deletions server/src/setup/meilisearch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use meilisearch_sdk::client::Client;
use meilisearch_sdk::settings::{Embedder, HuggingFaceEmbedderSettings, Settings};
use meilisearch_sdk::settings::{Embedder, OllamaEmbedderSettings, Settings};
use meilisearch_sdk::tasks::Task;
use serde_json::Value;
use std::collections::HashMap;
Expand Down Expand Up @@ -66,15 +66,11 @@ pub async fn setup(client: &Client, vector_search: bool) -> anyhow::Result<()> {
.wait_for_completion(client, POLLING_RATE, TIMEOUT)
.await?;
let entries = client.index("entries");
let en_embedder =Embedder::HuggingFace(HuggingFaceEmbedderSettings{
model: Some("BAAI/bge-base-en-v1.5".to_string()),
let en_embedder = Embedder::Ollama(OllamaEmbedderSettings{
api_key: None,
url: match std::env::var("MEILI_OLLAMA_URL").ok(){ None=>None,Some(s) if s.trim().is_empty()=> None,Some(s)=>Some(s)},
model: "mxbai-embed-large".to_string(),
document_template: Some("A room titled '{{doc.name}}' with type '{{doc.type_common_name}}' used as '{{doc.usage}}'".to_string()),
..Default::default()
});
let _de_embedder=Embedder::HuggingFace(HuggingFaceEmbedderSettings{
model: Some("google-bert/bert-base-german-cased".to_string()),
document_template: Some("Ein Raum '{{doc.name}}' vom typ '{{doc.type_common_name}}' benutzt als '{{doc.usage}}'".to_string()),
..Default::default()
});

let mut settings = Settings::new()
Expand Down

0 comments on commit 0b222d2

Please sign in to comment.