SqliteVec BuildInsertCommand is slow as it does not reuse a single command for inserts
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 68/100
Línea de trabajo
Start in MEVD/src/SqliteVec/SqliteCommandBuilder.cs, especially the cited lines around BuildInsertCommand and its parameter construction. Trace how insert commands are built and executed, then verify that the command text and parameter bindings remain reusable across records while key-returning and non-returning paths behave as expected.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
BuildInsertCommand constructs a chained multi-row INSERT with record-index-suffixed parameter names for every batch, so the CommandText and parameter names change with every call and Microsoft.Data.Sqlite cannot reuse any prepared statement, re-preparing all statements and allocating all parameters per batch.
Steps to reproduce
- Create a collection with a string key, one data property and a 256-dimension vector.
- Upsert batches of 200 records repeatedly and profile, or simply inspect the DbCommand produced by a batch.
- Observe the CommandText: Rather than one insert statement that is reused for each record, it is multiple statements, one statement per record, with parameter names like @Content13 embedding the record index, and it differs for every batch.
Expected behavior
The SQL text for an insert is stable across records so the provider's per-command prepared statement cache and parameter bindings can be reused, and only values are re-bound per record.
Actual behavior
Every batch builds a multi-kilobyte CommandText and a large set of SqliteParameter objects. For a 200-record batch 200 statements are added to the CommandText.
Analysis
The connector builds one INSERT per record inside a loop over the records, and derives parameter names from the record index:
Microsoft.Data.Sqlite caches prepared statements on the SqliteCommand instance and reuses them only while the CommandText is unchanged. Because the generated text embeds per-record parameter names and grows with the batch, no reuse across records is possible.
Additionally the data insert always runs through ExecuteReaderAsync even when no database-generated key needs to be read back, adding a reader allocation and result-set handling per batch.
Cause
Statement preparation cost scales with the number of records per batch, per operation, because the command is both rebuilt per operation and structured so each record has its own uniquely named parameters.
Possible fix
Build one fixed single-row INSERT command per table per operation (INSERT OR REPLACE INTO "t" (...) VALUES (@Key, @Content, ...)), prepare it once, and loop over the records re-binding parameter values only. Keep a RETURNING variant only for the database-generated int or long key case, and use ExecuteNonQueryAsync otherwise.
Environment
- OS: Windows 11 and Linux
- Package: CommunityToolkit.VectorData.SqliteVec 1.0.1-preview
- Microsoft.Data.Sqlite 10.x, sqlite-vec 0.1.7-alpha.2.1
- Lenguaje dominante
- C#
- Estrellas
- 8
- Forks
- 8
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 8
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de CommunityToolkit/AI
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
CommunityToolkit/AI#19 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
CommunityToolkit/AI#61 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
CommunityToolkit/AI#59 ·
-
Report all Cosmos DB emulator issuesQuizá libre de nuevo @adamsitnik la tomó hace 97 días y no hay ningún pull request abierto. Abierto
CommunityToolkit/AI#23 · 1 asignado ·
-
Make Azure SQL tests conditionalAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
CommunityToolkit/AI#20 ·
Todos los issues de CommunityToolkit/AI
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
area:re1 bounty help wanted needs-game
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
StackExchange/StackExchange.Redis#3274 ·
Los mantenedores suelen responder en 1 día
-
affected/v17 affected/v18 area/frontend type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
umbraco/Umbraco-CMS#24186 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 3 días