mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-01 07:03:10 +02:00
user restricted to own objects
This commit is contained in:
@@ -29,6 +29,7 @@ use surrealdb::{engine::any::Any, Surreal};
|
||||
/// * `db_client` - SurrealDB client for database operations
|
||||
/// * `openai_client` - OpenAI client for vector embeddings generation
|
||||
/// * `query` - The search query string to find relevant knowledge entities
|
||||
/// * 'user_id' - The user id of the current user
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Result<Vec<KnowledgeEntity>, ProcessingError>` - A deduplicated vector of relevant
|
||||
@@ -37,6 +38,7 @@ pub async fn combined_knowledge_entity_retrieval(
|
||||
db_client: &Surreal<Any>,
|
||||
openai_client: &async_openai::Client<async_openai::config::OpenAIConfig>,
|
||||
query: &str,
|
||||
user_id: &str,
|
||||
) -> Result<Vec<KnowledgeEntity>, ProcessingError> {
|
||||
// info!("Received input: {:?}", query);
|
||||
|
||||
@@ -47,6 +49,7 @@ pub async fn combined_knowledge_entity_retrieval(
|
||||
db_client,
|
||||
"knowledge_entity".to_string(),
|
||||
openai_client,
|
||||
user_id,
|
||||
),
|
||||
find_items_by_vector_similarity(
|
||||
5,
|
||||
@@ -54,6 +57,7 @@ pub async fn combined_knowledge_entity_retrieval(
|
||||
db_client,
|
||||
"text_chunk".to_string(),
|
||||
openai_client,
|
||||
user_id,
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -9,11 +9,12 @@ use crate::{error::ProcessingError, utils::embedding::generate_embedding};
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `take`: The number of items to retrieve from the database.
|
||||
/// * `input_text`: The text to generate embeddings for.
|
||||
/// * `db_client`: The SurrealDB client to use for querying the database.
|
||||
/// * `table`: The table to query in the database.
|
||||
/// * `openai_client`: The OpenAI client to use for generating embeddings.
|
||||
/// * `take` - The number of items to retrieve from the database.
|
||||
/// * `input_text` - The text to generate embeddings for.
|
||||
/// * `db_client` - The SurrealDB client to use for querying the database.
|
||||
/// * `table` - The table to query in the database.
|
||||
/// * `openai_client` - The OpenAI client to use for generating embeddings.
|
||||
/// * 'user_id`- The user id of the current user.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
@@ -21,13 +22,14 @@ use crate::{error::ProcessingError, utils::embedding::generate_embedding};
|
||||
///
|
||||
/// # Type Parameters
|
||||
///
|
||||
/// * `T`: The type to deserialize the query results into. Must implement `serde::Deserialize`.
|
||||
/// * `T` - The type to deserialize the query results into. Must implement `serde::Deserialize`.
|
||||
pub async fn find_items_by_vector_similarity<T>(
|
||||
take: u8,
|
||||
input_text: &str,
|
||||
db_client: &Surreal<Any>,
|
||||
table: String,
|
||||
openai_client: &async_openai::Client<async_openai::config::OpenAIConfig>,
|
||||
user_id: &str,
|
||||
) -> Result<Vec<T>, ProcessingError>
|
||||
where
|
||||
T: for<'de> serde::Deserialize<'de>,
|
||||
@@ -36,7 +38,7 @@ where
|
||||
let input_embedding = generate_embedding(openai_client, input_text).await?;
|
||||
|
||||
// Construct the query
|
||||
let closest_query = format!("SELECT *, vector::distance::knn() AS distance FROM {} WHERE embedding <|{},40|> {:?} ORDER BY distance", table, take, input_embedding);
|
||||
let closest_query = format!("SELECT *, vector::distance::knn() AS distance FROM {} WHERE embedding <|{},40|> {:?} AND user_id = '{}' ORDER BY distance", table, take, input_embedding, user_id);
|
||||
|
||||
// Perform query and deserialize to struct
|
||||
let closest_entities: Vec<T> = db_client.query(closest_query).await?.take(0)?;
|
||||
|
||||
Reference in New Issue
Block a user