mirror of
https://github.com/perstarkse/minne.git
synced 2026-07-08 13:55:23 +02:00
fix: load embedding dimensions once per persist and trim vector search select.
This commit is contained in:
@@ -48,6 +48,7 @@ const STORE_RELATIONSHIPS: &str = r"
|
||||
pub(super) async fn store_vector_chunks(
|
||||
db: &SurrealDbClient,
|
||||
task_id: &str,
|
||||
embedding_dimensions: usize,
|
||||
chunks: Vec<EmbeddedTextChunk>,
|
||||
) -> Result<usize, AppError> {
|
||||
let chunk_count = chunks.len();
|
||||
@@ -58,7 +59,13 @@ pub(super) async fn store_vector_chunks(
|
||||
chunk_len = embedded.chunk.chunk.chars().count(),
|
||||
"chunk persisted"
|
||||
);
|
||||
TextChunk::store_with_embedding(embedded.chunk, embedded.embedding, db).await?;
|
||||
TextChunk::store_with_embedding(
|
||||
embedded.chunk,
|
||||
embedded.embedding,
|
||||
embedding_dimensions,
|
||||
db,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(chunk_count)
|
||||
@@ -71,11 +78,18 @@ pub(super) async fn store_vector_chunks(
|
||||
pub(super) async fn store_graph_entities(
|
||||
db: &SurrealDbClient,
|
||||
tuning: &IngestionTuning,
|
||||
embedding_dimensions: usize,
|
||||
entities: Vec<EmbeddedKnowledgeEntity>,
|
||||
relationships: Vec<KnowledgeRelationship>,
|
||||
) -> Result<(), AppError> {
|
||||
for embedded in entities {
|
||||
KnowledgeEntity::store_with_embedding(embedded.entity, embedded.embedding, db).await?;
|
||||
KnowledgeEntity::store_with_embedding(
|
||||
embedded.entity,
|
||||
embedded.embedding,
|
||||
embedding_dimensions,
|
||||
db,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if relationships.is_empty() {
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
|
||||
use common::{
|
||||
error::AppError,
|
||||
storage::{indexes::rebuild, types::ingestion_payload::IngestionPayload},
|
||||
storage::{
|
||||
indexes::rebuild,
|
||||
types::{ingestion_payload::IngestionPayload, system_settings::SystemSettings},
|
||||
},
|
||||
};
|
||||
use state_machines::core::GuardError;
|
||||
use tracing::{debug, instrument};
|
||||
@@ -155,8 +158,26 @@ pub async fn persist(
|
||||
let entity_count = entities.len();
|
||||
let relationship_count = relationships.len();
|
||||
|
||||
let chunk_count = store_vector_chunks(ctx.db, ctx.task_id.as_str(), chunks).await?;
|
||||
store_graph_entities(ctx.db, &ctx.pipeline_config.tuning, entities, relationships).await?;
|
||||
let settings = SystemSettings::get_current(ctx.db).await?;
|
||||
let embedding_dimensions = usize::try_from(settings.embedding_dimensions).map_err(|_| {
|
||||
AppError::InternalError("system_settings.embedding_dimensions exceeds usize::MAX".into())
|
||||
})?;
|
||||
|
||||
let chunk_count = store_vector_chunks(
|
||||
ctx.db,
|
||||
ctx.task_id.as_str(),
|
||||
embedding_dimensions,
|
||||
chunks,
|
||||
)
|
||||
.await?;
|
||||
store_graph_entities(
|
||||
ctx.db,
|
||||
&ctx.pipeline_config.tuning,
|
||||
embedding_dimensions,
|
||||
entities,
|
||||
relationships,
|
||||
)
|
||||
.await?;
|
||||
ctx.db.store_item(text_content).await?;
|
||||
rebuild(ctx.db).await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user