Skip to content

Commit 89bddea

Browse files
committed
Update function names
1 parent 6aec315 commit 89bddea

5 files changed

Lines changed: 56 additions & 56 deletions

File tree

API.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sqlite-memory enables semantic search over text content stored in SQLite. It:
3232

3333
## Sync Behavior
3434

35-
All `memory_sync_*` functions use **content-hash change detection** to avoid redundant embedding computation. Each piece of content is hashed before processing — if the hash already exists in the database, the content is skipped.
35+
All `memory_add_*` functions use **content-hash change detection** to avoid redundant embedding computation. Each piece of content is hashed before processing — if the hash already exists in the database, the content is skipped.
3636

3737
### Change Detection
3838

@@ -201,7 +201,7 @@ SELECT memory_get_option('provider');
201201

202202
### Memory Management Functions
203203

204-
#### `memory_sync_text(content TEXT [, context TEXT])`
204+
#### `memory_add_text(content TEXT [, context TEXT])`
205205

206206
Syncs text content to memory. Duplicate content (same hash) is skipped automatically.
207207

@@ -223,15 +223,15 @@ Syncs text content to memory. Duplicate content (same hash) is skipped automatic
223223
**Example:**
224224
```sql
225225
-- Add text without context
226-
SELECT memory_sync_text('SQLite is a C-language library that implements a small, fast, self-contained SQL database engine.');
226+
SELECT memory_add_text('SQLite is a C-language library that implements a small, fast, self-contained SQL database engine.');
227227

228228
-- Add text with context
229-
SELECT memory_sync_text('Important meeting notes from 2024-01-15...', 'meetings');
229+
SELECT memory_add_text('Important meeting notes from 2024-01-15...', 'meetings');
230230
```
231231

232232
---
233233

234-
#### `memory_sync_file(path TEXT [, context TEXT])`
234+
#### `memory_add_file(path TEXT [, context TEXT])`
235235

236236
Syncs a file to memory. Unchanged files are skipped; modified files are atomically replaced.
237237

@@ -251,13 +251,13 @@ Syncs a file to memory. Unchanged files are skipped; modified files are atomical
251251

252252
**Example:**
253253
```sql
254-
SELECT memory_sync_file('/docs/readme.md');
255-
SELECT memory_sync_file('/docs/api.md', 'documentation');
254+
SELECT memory_add_file('/docs/readme.md');
255+
SELECT memory_add_file('/docs/api.md', 'documentation');
256256
```
257257

258258
---
259259

260-
#### `memory_sync_directory(path TEXT [, context TEXT])`
260+
#### `memory_add_directory(path TEXT [, context TEXT])`
261261

262262
Synchronizes a directory with memory. Adds new files, reindexes modified files, and removes entries for deleted files.
263263

@@ -283,13 +283,13 @@ Synchronizes a directory with memory. Adds new files, reindexes modified files,
283283

284284
**Example:**
285285
```sql
286-
SELECT memory_sync_directory('/path/to/docs');
286+
SELECT memory_add_directory('/path/to/docs');
287287
-- Returns: 42 (number of new files processed)
288288

289-
SELECT memory_sync_directory('/project/notes', 'project-notes');
289+
SELECT memory_add_directory('/project/notes', 'project-notes');
290290

291291
-- Safe to call again — unchanged files are skipped
292-
SELECT memory_sync_directory('/path/to/docs');
292+
SELECT memory_add_directory('/path/to/docs');
293293
-- Returns: 0 (nothing changed)
294294
```
295295

@@ -477,7 +477,7 @@ The extension tracks two timestamps for each memory:
477477

478478
### `created_at`
479479

480-
- Set automatically when content is added via `memory_sync_text`, `memory_sync_file`, or `memory_sync_directory`
480+
- Set automatically when content is added via `memory_add_text`, `memory_add_file`, or `memory_add_directory`
481481
- Stored as Unix timestamp (seconds since 1970-01-01 00:00:00 UTC)
482482
- Never updated after initial creation
483483

@@ -518,8 +518,8 @@ SELECT memory_set_option('max_tokens', 512);
518518
SELECT memory_set_option('min_score', 0.75);
519519

520520
-- Add content
521-
SELECT memory_sync_text('SQLite is a C library that provides a lightweight disk-based database.', 'sqlite-docs');
522-
SELECT memory_sync_directory('/docs/sqlite', 'sqlite-docs');
521+
SELECT memory_add_text('SQLite is a C library that provides a lightweight disk-based database.', 'sqlite-docs');
522+
SELECT memory_add_directory('/docs/sqlite', 'sqlite-docs');
523523

524524
-- Search
525525
SELECT path, snippet, ranking
@@ -547,9 +547,9 @@ SELECT memory_clear();
547547

548548
```sql
549549
-- Add memories with different contexts
550-
SELECT memory_sync_text('Meeting notes...', 'meetings');
551-
SELECT memory_sync_text('API documentation...', 'api-docs');
552-
SELECT memory_sync_text('Tutorial content...', 'tutorials');
550+
SELECT memory_add_text('Meeting notes...', 'meetings');
551+
SELECT memory_add_text('API documentation...', 'api-docs');
552+
SELECT memory_add_text('Tutorial content...', 'tutorials');
553553

554554
-- Search within a context
555555
SELECT * FROM memory_search
@@ -619,6 +619,6 @@ Errors can be caught using standard SQLite error handling mechanisms.
619619

620620
```sql
621621
-- Example error handling in application code
622-
SELECT memory_sync_text(123); -- Error: expects TEXT parameter
622+
SELECT memory_add_text(123); -- Error: expects TEXT parameter
623623
SELECT memory_delete('abc'); -- Error: expects INTEGER parameter
624624
```

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ SELECT memory_set_model('local', '/path/to/nomic-embed-text-v1.5.Q8_0.gguf');
8383
-- SELECT memory_set_apikey('your-vectorspace-api-key');
8484

8585
-- Add some knowledge
86-
SELECT memory_sync_text('SQLite is a C-language library that implements a small, fast,
86+
SELECT memory_add_text('SQLite is a C-language library that implements a small, fast,
8787
self-contained, high-reliability, full-featured, SQL database engine. SQLite is the
8888
most used database engine in the world.', 'sqlite-docs');
8989

90-
SELECT memory_sync_text('Vector databases store data as high-dimensional vectors,
90+
SELECT memory_add_text('Vector databases store data as high-dimensional vectors,
9191
enabling similarity search. They are essential for semantic search, recommendation
9292
systems, and AI applications.', 'concepts');
9393

9494
-- Sync an entire documentation directory
95-
SELECT memory_sync_directory('/path/to/docs', 'project-docs');
95+
SELECT memory_add_directory('/path/to/docs', 'project-docs');
9696

9797
-- Search your memory semantically
9898
SELECT path, snippet, ranking
@@ -124,7 +124,7 @@ conn.execute("SELECT memory_set_model('local', './models/nomic-embed-text-v1.5.Q
124124

125125
# Store conversation context
126126
def remember(content, context="conversation"):
127-
conn.execute("SELECT memory_sync_text(?, ?)", (content, context))
127+
conn.execute("SELECT memory_add_text(?, ?)", (content, context))
128128
conn.commit()
129129

130130
# Retrieve relevant memories
@@ -147,11 +147,11 @@ memories = recall("what's the project timeline")
147147

148148
## Intelligent Sync
149149

150-
All `memory_sync_*` functions use content-hash change detection to avoid redundant work:
150+
All `memory_add_*` functions use content-hash change detection to avoid redundant work:
151151

152-
- **`memory_sync_text`** — Computes a hash of the content. If the same content was already indexed, it is skipped entirely. No duplicate embeddings are ever created.
153-
- **`memory_sync_file`** — Reads the file and hashes its content. If the file was previously indexed with different content, the old entry (chunks, embeddings, FTS) is atomically replaced. Unchanged files are skipped.
154-
- **`memory_sync_directory`** — Performs a full two-phase sync:
152+
- **`memory_add_text`** — Computes a hash of the content. If the same content was already indexed, it is skipped entirely. No duplicate embeddings are ever created.
153+
- **`memory_add_file`** — Reads the file and hashes its content. If the file was previously indexed with different content, the old entry (chunks, embeddings, FTS) is atomically replaced. Unchanged files are skipped.
154+
- **`memory_add_directory`** — Performs a full two-phase sync:
155155
1. **Cleanup**: Removes database entries for files that no longer exist on disk
156156
2. **Scan**: Recursively processes all matching files — adding new ones, replacing modified ones, and skipping unchanged ones
157157

@@ -240,7 +240,7 @@ make test
240240

241241
- **Local Engine**: Built-in llama.cpp for on-device embeddings (requires GGUF model)
242242
- **Remote Engine**: [vectors.space](https://vectors.space) API for cloud embeddings (requires free API key)
243-
- **File I/O**: `memory_sync_file` and `memory_sync_directory` functions
243+
- **File I/O**: `memory_add_file` and `memory_add_directory` functions
244244

245245
You can also combine options manually:
246246

src/sqlite-memory.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ SQLITE_EXTENSION_INIT1
5656
#define DBMEM_SETTINGS_KEY_TEXT_WEIGHT "text_weight"
5757
#define DBMEM_SETTINGS_KEY_MIN_SCORE "min_score"
5858
#define DBMEM_SETTINGS_KEY_UPDATE_ACCESS "update_access"
59-
#define DBMEM_SETTINGS_KEY_EMBEDDING_CACHE "embedding_cache"
60-
#define DBMEM_SETTINGS_KEY_CACHE_MAX_ENTRIES "cache_max_entries"
61-
#define DBMEM_SETTINGS_KEY_SEARCH_OVERSAMPLE "search_oversample"
59+
#define DBMEM_SETTINGS_KEY_EMBEDDING_CACHE "embedding_cache"
60+
#define DBMEM_SETTINGS_KEY_CACHE_MAX_ENTRIES "cache_max_entries"
61+
#define DBMEM_SETTINGS_KEY_SEARCH_OVERSAMPLE "search_oversample"
6262

6363
// default values from https://docs.openclaw.ai/concepts/memory
6464
#define DEFAULT_CHARS_PER_TOKEN 4 // Approximate number of characters per token (GPT ≈ 4, Claude ≈ 3.5)
65-
#define DEFAULT_MAX_TOKENS 400
66-
#define DEFAULT_OVERLAY_TOKENS 80
67-
#define DEFAULT_MAX_SNIPPET_CHARS 700
68-
#define DEFAULT_MAX_RESULTS 20
69-
#define DEFAULT_VECTOR_WEIGHT 0.5
70-
#define DEFAULT_TEXT_WEIGHT 0.5
71-
#define DEFAULT_MIN_SCORE 0.7
65+
#define DEFAULT_MAX_TOKENS 400 // Maximum tokens per chunk
66+
#define DEFAULT_OVERLAY_TOKENS 80 // Token overlap between consecutive chunks
67+
#define DEFAULT_MAX_SNIPPET_CHARS 700 // Maximum characters for search result snippets
68+
#define DEFAULT_MAX_RESULTS 20 // Maximum number of search results
69+
#define DEFAULT_VECTOR_WEIGHT 0.6 // Semantic similarity weight in hybrid search scoring
70+
#define DEFAULT_TEXT_WEIGHT 0.4 // Full-text match weight in hybrid search scoring
71+
#define DEFAULT_MIN_SCORE 0.7 // Minimum score threshold to filter irrelevant results
7272

7373
struct dbmem_context {
7474
// Database and engine
@@ -1367,10 +1367,10 @@ static int dbmem_scan_callback (const char *path, void *data) {
13671367
return rc;
13681368
}
13691369

1370-
static void dbmem_sync_text (sqlite3_context *context, int argc, sqlite3_value **argv) {
1370+
static void dbmem_add_text (sqlite3_context *context, int argc, sqlite3_value **argv) {
13711371
// sanity check type
13721372
if (sqlite3_value_type(argv[0]) != SQLITE_TEXT) {
1373-
sqlite3_result_error(context, "The function memory_sync_text expects a parameter of type TEXT", SQLITE_ERROR);
1373+
sqlite3_result_error(context, "The function memory_add_text expects a parameter of type TEXT", SQLITE_ERROR);
13741374
return;
13751375
}
13761376

@@ -1392,10 +1392,10 @@ static void dbmem_sync_text (sqlite3_context *context, int argc, sqlite3_value *
13921392
}
13931393

13941394
#ifndef DBMEM_OMIT_IO
1395-
static void dbmem_sync_file (sqlite3_context *context, int argc, sqlite3_value **argv) {
1395+
static void dbmem_add_file (sqlite3_context *context, int argc, sqlite3_value **argv) {
13961396
// sanity check type
13971397
if (sqlite3_value_type(argv[0]) != SQLITE_TEXT) {
1398-
sqlite3_result_error(context, "The function memory_sync_file expects the first parameter to be of type TEXT", SQLITE_ERROR);
1398+
sqlite3_result_error(context, "The function memory_add_file expects the first parameter to be of type TEXT", SQLITE_ERROR);
13991399
return;
14001400
}
14011401

@@ -1439,10 +1439,10 @@ static void dbmem_database_delete_missing_files (sqlite3 *db, const char *dir_pa
14391439
sqlite3_free_table(table);
14401440
}
14411441

1442-
static void dbmem_sync_directory (sqlite3_context *context, int argc, sqlite3_value **argv) {
1442+
static void dbmem_add_directory (sqlite3_context *context, int argc, sqlite3_value **argv) {
14431443
// sanity check type
14441444
if (sqlite3_value_type(argv[0]) != SQLITE_TEXT) {
1445-
sqlite3_result_error(context, "The function memory_sync_directory expects the first parameter to be of type TEXT", SQLITE_ERROR);
1445+
sqlite3_result_error(context, "The function memory_add_directory expects the first parameter to be of type TEXT", SQLITE_ERROR);
14461446
return;
14471447
}
14481448

@@ -1511,23 +1511,23 @@ SQLITE_DBMEMORY_API int sqlite3_memory_init (sqlite3 *db, char **pzErrMsg, const
15111511
if (rc != SQLITE_OK) return rc;
15121512

15131513
#ifndef DBMEM_OMIT_IO
1514-
rc = sqlite3_create_function_v2(db, "memory_sync_file", 1, SQLITE_UTF8, ctx, dbmem_sync_file, NULL, NULL, NULL);
1514+
rc = sqlite3_create_function_v2(db, "memory_add_file", 1, SQLITE_UTF8, ctx, dbmem_add_file, NULL, NULL, NULL);
15151515
if (rc != SQLITE_OK) return rc;
1516-
1517-
rc = sqlite3_create_function_v2(db, "memory_sync_file", 2, SQLITE_UTF8, ctx, dbmem_sync_file, NULL, NULL, NULL);
1516+
1517+
rc = sqlite3_create_function_v2(db, "memory_add_file", 2, SQLITE_UTF8, ctx, dbmem_add_file, NULL, NULL, NULL);
15181518
if (rc != SQLITE_OK) return rc;
1519-
1520-
rc = sqlite3_create_function_v2(db, "memory_sync_directory", 1, SQLITE_UTF8, ctx, dbmem_sync_directory, NULL, NULL, NULL);
1519+
1520+
rc = sqlite3_create_function_v2(db, "memory_add_directory", 1, SQLITE_UTF8, ctx, dbmem_add_directory, NULL, NULL, NULL);
15211521
if (rc != SQLITE_OK) return rc;
15221522

1523-
rc = sqlite3_create_function_v2(db, "memory_sync_directory", 2, SQLITE_UTF8, ctx, dbmem_sync_directory, NULL, NULL, NULL);
1523+
rc = sqlite3_create_function_v2(db, "memory_add_directory", 2, SQLITE_UTF8, ctx, dbmem_add_directory, NULL, NULL, NULL);
15241524
if (rc != SQLITE_OK) return rc;
15251525
#endif
15261526

1527-
rc = sqlite3_create_function_v2(db, "memory_sync_text", 1, SQLITE_UTF8, ctx, dbmem_sync_text, NULL, NULL, NULL);
1527+
rc = sqlite3_create_function_v2(db, "memory_add_text", 1, SQLITE_UTF8, ctx, dbmem_add_text, NULL, NULL, NULL);
15281528
if (rc != SQLITE_OK) return rc;
15291529

1530-
rc = sqlite3_create_function_v2(db, "memory_sync_text", 2, SQLITE_UTF8, ctx, dbmem_sync_text, NULL, NULL, NULL);
1530+
rc = sqlite3_create_function_v2(db, "memory_add_text", 2, SQLITE_UTF8, ctx, dbmem_add_text, NULL, NULL, NULL);
15311531
if (rc != SQLITE_OK) return rc;
15321532

15331533
rc = sqlite3_create_function_v2(db, "memory_delete", 1, SQLITE_UTF8, ctx, dbmem_delete, NULL, NULL, NULL);

src/sqlite-memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
extern "C" {
2727
#endif
2828

29-
#define SQLITE_DBMEMORY_VERSION "0.5.5"
29+
#define SQLITE_DBMEMORY_VERSION "0.6.0"
3030

3131
// public API
3232
SQLITE_DBMEMORY_API int sqlite3_memory_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);

test/unittest.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ static int insert_fake_content(sqlite3 *db, sqlite3_int64 hash, const char *path
17901790
}
17911791

17921792
TEST(sqlite_sync_directory_removes_deleted) {
1793-
// Test that memory_sync_directory removes entries for files no longer on disk
1793+
// Test that memory_add_directory removes entries for files no longer on disk
17941794
sqlite3 *db = open_test_db();
17951795
ASSERT(db != NULL);
17961796

@@ -1828,7 +1828,7 @@ TEST(sqlite_sync_directory_removes_deleted) {
18281828

18291829
// Sync — should remove the entry for gone.md, skip keep.md (hash match)
18301830
sqlite3_int64 result;
1831-
rc = exec_get_int(db, "SELECT memory_sync_directory('/tmp/dbmem_test_sync_del');", &result);
1831+
rc = exec_get_int(db, "SELECT memory_add_directory('/tmp/dbmem_test_sync_del');", &result);
18321832
ASSERT_EQ(rc, SQLITE_OK);
18331833

18341834
// Only keep.md entry should remain
@@ -1880,7 +1880,7 @@ TEST(sqlite_sync_directory_removes_all_deleted) {
18801880

18811881
// Sync — all files gone, all entries should be removed
18821882
sqlite3_int64 result;
1883-
rc = exec_get_int(db, "SELECT memory_sync_directory('/tmp/dbmem_test_sync_allgone');", &result);
1883+
rc = exec_get_int(db, "SELECT memory_add_directory('/tmp/dbmem_test_sync_allgone');", &result);
18841884
ASSERT_EQ(rc, SQLITE_OK);
18851885

18861886
rc = exec_get_int(db, "SELECT COUNT(*) FROM dbmem_content;", &count);
@@ -1917,7 +1917,7 @@ TEST(sqlite_sync_directory_skips_unchanged) {
19171917

19181918
// Sync — file exists with matching hash, should be skipped
19191919
sqlite3_int64 result;
1920-
rc = exec_get_int(db, "SELECT memory_sync_directory('/tmp/dbmem_test_sync_skip', 'notes');", &result);
1920+
rc = exec_get_int(db, "SELECT memory_add_directory('/tmp/dbmem_test_sync_skip', 'notes');", &result);
19211921
ASSERT_EQ(rc, SQLITE_OK);
19221922

19231923
// Entry still exists unchanged (no duplication)

0 commit comments

Comments
 (0)