-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsqlite-memory.h
More file actions
92 lines (74 loc) · 3.2 KB
/
Copy pathsqlite-memory.h
File metadata and controls
92 lines (74 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// sqlite-memory.h
// sqlitememory
//
// Created by Marco Bambini on 30/01/26.
//
#ifndef __SQLITE_DBMEMORY__
#define __SQLITE_DBMEMORY__
#ifndef SQLITE_CORE
#include "sqlite3ext.h"
#else
#include "sqlite3.h"
#endif
#include <stdbool.h>
#ifdef _WIN32
#define SQLITE_DBMEMORY_API __declspec(dllexport)
#else
#define SQLITE_DBMEMORY_API
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define SQLITE_DBMEMORY_VERSION "1.3.5"
// public API
SQLITE_DBMEMORY_API int sqlite3_memory_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
// Custom embedding provider API
// Allows registering a user-defined embedding engine that works regardless of
// DBMEM_OMIT_LOCAL_ENGINE / DBMEM_OMIT_REMOTE_ENGINE compile flags.
// The api_key set via memory_set_apikey() is passed to the init callback.
typedef struct dbmem_context dbmem_context;
typedef struct {
int n_tokens;
bool truncated;
int n_embd;
float *embedding; // Engine-owned buffer, valid until next call or free
} dbmem_embedding_result_t;
typedef struct {
// Called when memory_set_model(provider, model) matches this provider, or
// lazily on first embedding use when provider/model were loaded from settings.
// api_key is the value set via memory_set_apikey() (may be NULL).
// xdata is the user-supplied generic pointer from the struct.
// Return opaque engine pointer, or NULL on error (fill err_msg).
void *(*init)(const char *model, const char *api_key, void *xdata, char err_msg[1024]);
// Compute embedding for text. Return 0 on success, non-zero on error.
int (*compute)(void *engine, const char *text, int text_len, void *xdata, dbmem_embedding_result_t *result);
// Free the engine. Called on context teardown or model change. May be NULL.
void (*free)(void *engine, void *xdata);
// User-supplied generic data pointer, passed to all callbacks.
void *xdata;
} dbmem_provider_t;
// Register a custom embedding provider.
// provider_name: matched against the first argument of memory_set_model().
// Returns SQLITE_OK on success.
SQLITE_DBMEMORY_API int sqlite3_memory_register_provider (sqlite3 *db, const char *provider_name, const dbmem_provider_t *provider);
void *dbmem_context_engine (dbmem_context *ctx, bool *is_local);
int dbmem_context_ensure_engine (dbmem_context *ctx);
bool dbmem_context_is_custom (dbmem_context *ctx);
bool dbmem_context_load_vector (dbmem_context *ctx);
bool dbmem_context_sync_available (dbmem_context *ctx);
bool dbmem_context_perform_fts (dbmem_context *ctx);
int dbmem_context_max_results (dbmem_context *ctx);
double dbmem_context_vector_weight (dbmem_context *ctx);
double dbmem_context_text_weight (dbmem_context *ctx);
double dbmem_context_min_score (dbmem_context *ctx);
bool dbmem_context_update_access (dbmem_context *ctx);
int dbmem_context_search_oversample (dbmem_context *ctx);
const char *dbmem_context_errmsg (dbmem_context *ctx);
const char *dbmem_context_apikey (dbmem_context *ctx);
void dbmem_context_set_error (dbmem_context *ctx, const char *str);
void dbmem_context_set_errorf (dbmem_context *ctx, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
#ifdef __cplusplus
}
#endif
#endif