@@ -251,8 +251,8 @@ ragnar_store_build_index_v2 <- function(store, type = c("vss", "fts")) {
251
251
r " --(
252
252
PRAGMA create_fts_index(
253
253
'chunks', -- input_table
254
- 'chunk_id', -- input_id
255
- 'context', 'text', -- *input_values
254
+ 'chunk_id', -- input_id
255
+ 'context', 'text', -- *input_values
256
256
overwrite = 1
257
257
);
258
258
)--"
@@ -277,9 +277,15 @@ ragnar_store_update_v2 <- function(store, chunks) {
277
277
S7_inherits(chunks , MarkdownDocumentChunks )
278
278
)
279
279
280
- # Chunks are not refering to any document, or the document doesn't have an origin.
281
- if (is.null(chunks @ document ) || is.na(chunks @ document @ origin ) || is.null(chunks @ document @ origin )) {
282
- stop(" Can't update chunks when the document does not specify a valid origin, use ragnar_store_insert instead." )
280
+ # Chunks are not referring to any document, or the document doesn't have an origin.
281
+ if (
282
+ is.null(chunks @ document ) ||
283
+ is.na(chunks @ document @ origin ) ||
284
+ is.null(chunks @ document @ origin )
285
+ ) {
286
+ stop(
287
+ " Can't update chunks when the document does not specify a valid origin, use `ragnar_store_insert()` instead."
288
+ )
283
289
}
284
290
285
291
if (" text" %in% names(chunks )) {
@@ -317,11 +323,12 @@ ragnar_store_update_v2 <- function(store, chunks) {
317
323
text = as.character(chunks @ document )
318
324
)
319
325
326
+ if (! is.null(store @ embed ) && ! " embedding" %in% names(chunks )) {
327
+ chunks $ embedding <-
328
+ store @ embed(with(chunks , stri_c(context %| % " " , " \n " , text )))
329
+ }
330
+
320
331
embeddings <- chunks | >
321
- mutate(
322
- embedding = store @ embed(stri_c(context , " \n " , text )),
323
- text = NULL
324
- ) | >
325
332
select(any_of(dbListFields(con , " embeddings" ))) | >
326
333
vctrs :: vec_cast(store @ schema )
327
334
@@ -383,9 +390,9 @@ ragnar_store_insert_v2 <- function(store, chunks, replace_existing = FALSE) {
383
390
} else {
384
391
chunks $ text <- stri_sub(chunks @ document , chunks $ start , chunks $ end )
385
392
}
386
-
387
393
if (! is.null(store @ embed ) && ! " embedding" %in% names(chunks )) {
388
- chunks $ embedding <- store @ embed(with(chunks , stri_c(context , " \n " , text )))
394
+ chunks $ embedding <-
395
+ store @ embed(with(chunks , stri_c(context %| % " " , " \n " , text )))
389
396
}
390
397
391
398
con <- store @ con
0 commit comments