Skip to main content

Queryable

Struct Queryable 

Source
pub struct Queryable {
    pub query_type: QueryType,
    pub text: String,
}
Expand description

A single query with its target backend type.

Fields§

§query_type: QueryType

Query type.

§text: String

Query text.

Implementations§

Source§

impl Queryable

Source

pub fn new(query_type: QueryType, text: impl Into<String>) -> Self

Create a new queryable.

Source

pub fn lex(text: impl Into<String>) -> Self

Create a lexical query.

Examples found in repository?
examples/query_expansion.rs (line 63)
13fn main() -> Result<()> {
14    let db_path = std::env::temp_dir().join("qmd_expansion.db");
15    let _ = std::fs::remove_file(&db_path);
16    let store = Store::open(&db_path)?;
17
18    let now = chrono::Utc::now().to_rfc3339();
19    for (name, content) in SAMPLE_DOCS {
20        let hash = Store::hash_content(content);
21        let title = Store::extract_title(content);
22        store.insert_content(&hash, content, &now)?;
23        store.insert_document("samples", name, &title, &hash, &now, &now)?;
24    }
25
26    let query = "rust error handling";
27    println!("Query: '{}'\n", query);
28
29    // Simple expansion
30    println!("Simple expansion:");
31    for q in expand_query_simple(query) {
32        let t = match q.query_type {
33            QueryType::Lex => "LEX",
34            QueryType::Vec => "VEC",
35            QueryType::Hyde => "HYD",
36        };
37        println!("  [{}] {}", t, q.text);
38    }
39
40    // Search with expanded queries
41    println!("\nSearch results:");
42    for q in expand_query_simple(query) {
43        if q.query_type == QueryType::Lex {
44            let n = store.search_fts(&q.text, 5, None)?.len();
45            println!("  '{}': {} results", q.text, n);
46        }
47    }
48
49    // LLM expansion
50    println!("\nLLM expansion:");
51    if GenerationEngine::is_available() {
52        let engine = GenerationEngine::load_default()?;
53        for q in engine.expand_query(query, true)? {
54            println!("  [{:?}] {}", q.query_type, q.text);
55        }
56    } else {
57        println!("  (not available)");
58    }
59
60    // Manual construction
61    println!("\nManual:");
62    for q in [
63        Queryable::lex("rust error"),
64        Queryable::vec("exception handling"),
65    ] {
66        println!("  [{:?}] {}", q.query_type, q.text);
67    }
68
69    let _ = std::fs::remove_file(&db_path);
70    Ok(())
71}
Source

pub fn vec(text: impl Into<String>) -> Self

Create a vector query.

Examples found in repository?
examples/query_expansion.rs (line 64)
13fn main() -> Result<()> {
14    let db_path = std::env::temp_dir().join("qmd_expansion.db");
15    let _ = std::fs::remove_file(&db_path);
16    let store = Store::open(&db_path)?;
17
18    let now = chrono::Utc::now().to_rfc3339();
19    for (name, content) in SAMPLE_DOCS {
20        let hash = Store::hash_content(content);
21        let title = Store::extract_title(content);
22        store.insert_content(&hash, content, &now)?;
23        store.insert_document("samples", name, &title, &hash, &now, &now)?;
24    }
25
26    let query = "rust error handling";
27    println!("Query: '{}'\n", query);
28
29    // Simple expansion
30    println!("Simple expansion:");
31    for q in expand_query_simple(query) {
32        let t = match q.query_type {
33            QueryType::Lex => "LEX",
34            QueryType::Vec => "VEC",
35            QueryType::Hyde => "HYD",
36        };
37        println!("  [{}] {}", t, q.text);
38    }
39
40    // Search with expanded queries
41    println!("\nSearch results:");
42    for q in expand_query_simple(query) {
43        if q.query_type == QueryType::Lex {
44            let n = store.search_fts(&q.text, 5, None)?.len();
45            println!("  '{}': {} results", q.text, n);
46        }
47    }
48
49    // LLM expansion
50    println!("\nLLM expansion:");
51    if GenerationEngine::is_available() {
52        let engine = GenerationEngine::load_default()?;
53        for q in engine.expand_query(query, true)? {
54            println!("  [{:?}] {}", q.query_type, q.text);
55        }
56    } else {
57        println!("  (not available)");
58    }
59
60    // Manual construction
61    println!("\nManual:");
62    for q in [
63        Queryable::lex("rust error"),
64        Queryable::vec("exception handling"),
65    ] {
66        println!("  [{:?}] {}", q.query_type, q.text);
67    }
68
69    let _ = std::fs::remove_file(&db_path);
70    Ok(())
71}
Source

pub fn hyde(text: impl Into<String>) -> Self

Create a HyDE query.

Trait Implementations§

Source§

impl Clone for Queryable

Source§

fn clone(&self) -> Queryable

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Queryable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more