You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: align and persist remote embedding result metadata (#6)
- Unify embedding result metadata: replace n_tokens_truncated with a
shared truncated boolean across local, remote, and custom engines.
- Persist n_tokens and truncated on dbmem_vault and dbmem_cache rows,
with schema versioning and automatic migration of existing databases.
- Parse the documented vectors.space envelope (output_dimension,
data[0].embedding, data[0].truncated, usage.request_tokens) instead
of a flat key scan.
- Add e2e coverage for multi-chunk retrieval and single-chunk inserts
around the provider token ceiling and model context window; search
tests print per-chunk n_tokens/truncated round-tripped through the API.
- Run extension unit tests in CI (with local-only build fixes), use
portable temp paths in sync tests, hash the sync fixture from disk,
and isolate curl's ./configure from inherited shell build envs.
- Update the C API reference for the truncated flag on custom provider
results.
Copy file name to clipboardExpand all lines: API.md
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -564,8 +564,8 @@ typedef struct {
564
564
**`dbmem_embedding_result_t` struct:**
565
565
```c
566
566
typedefstruct {
567
-
int n_tokens; // Number of tokens processed
568
-
int n_tokens_truncated; // Tokens that were truncated (0 if none)
567
+
int n_tokens; // Number of processed tokens (0 if unknown)
568
+
booltruncated; // True when the input was truncated before embedding
569
569
int n_embd; // Embedding dimension
570
570
float *embedding; // Embedding vector (engine-owned, valid until next call or free)
571
571
} dbmem_embedding_result_t;
@@ -574,6 +574,7 @@ typedef struct {
574
574
**Notes:**
575
575
- Works regardless of `DBMEM_OMIT_LOCAL_ENGINE` / `DBMEM_OMIT_REMOTE_ENGINE` compile flags
576
576
- The `embedding` buffer in `dbmem_embedding_result_t` must remain valid until the next `compute` call or `free` — it is engine-owned, not copied by the caller
577
+
-`n_tokens` is metadata about the processed input when the engine can provide it; `truncated` is a boolean flag, not a truncated-token count
577
578
- Only one custom provider can be registered per connection at a time; registering again replaces the previous one
578
579
- The provider struct is copied by value; the caller does not need to keep it alive after registration
579
580
@@ -596,7 +597,7 @@ static int my_compute(void *engine, const char *text, int text_len, void *xdata,
596
597
// ... fill vec with your embedding ...
597
598
result->n_embd = e->dimension;
598
599
result->n_tokens = text_len / 4;
599
-
result->n_tokens_truncated = 0;
600
+
result->truncated = false;
600
601
result->embedding = vec;
601
602
return 0;
602
603
}
@@ -769,6 +770,21 @@ FROM dbmem_content
769
770
WHERE last_accessed >0
770
771
ORDER BY last_accessed DESC
771
772
LIMIT10;
773
+
774
+
-- Tokens consumed and truncation per context
775
+
-- (n_tokens / truncated were added in schema version 2)
776
+
SELECT
777
+
COALESCE(c.context, '(none)') as context,
778
+
SUM(v.n_tokens) as tokens_processed,
779
+
SUM(v.truncated) as truncated_chunks
780
+
FROM dbmem_vault v
781
+
JOIN dbmem_content c ONc.hash=v.hash
782
+
GROUP BYc.context;
783
+
784
+
-- Chunks that the embedding model truncated on input
0 commit comments