From 4dbd14d404240662bbb40bf2592c938bb7052775 Mon Sep 17 00:00:00 2001 From: Praneeth Bedapudi Date: Tue, 22 Oct 2024 04:49:21 +0530 Subject: [PATCH] use vectorlite for embedding search Signed-off-by: Praneeth Bedapudi --- liteindex/kv_index.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/liteindex/kv_index.py b/liteindex/kv_index.py index ee58c3c..784364c 100644 --- a/liteindex/kv_index.py +++ b/liteindex/kv_index.py @@ -470,6 +470,9 @@ def update(self, items, reverse_order=False): key_hashes, ).fetchone()[0] + if total_old_size is None: + total_old_size = 0 + conn.execute( "UPDATE kv_index_num_metadata SET num = num + ? WHERE key = ?", ( @@ -554,7 +557,8 @@ def __run_eviction(self, conn): if self.eviction.max_size_in_mb: s = time.time() current_size_in_mb = conn.execute( - "SELECT num FROM kv_index_num_metadata WHERE key = current_size_in_mb" + "SELECT num FROM kv_index_num_metadata WHERE key = ?", + ("current_size_in_mb",), ).fetchone()[0] if current_size_in_mb >= self.eviction.max_size_in_mb: @@ -570,6 +574,8 @@ def __run_eviction(self, conn): if number_of_rows_to_evict == 0: return + + print('----', number_of_rows_to_evict, self.eviction.policy, self.eviction.max_size_in_mb, self.eviction.max_number_of_items) if not self.eviction.max_size_in_mb: if self.eviction.policy == EvictionCfg.EvictLRU: @@ -629,10 +635,7 @@ def popitem(self, reverse=True): def clear(self): with self.__connection as conn: conn.execute("DELETE FROM kv_index") - conn.execute( - "UPDATE kv_index_num_metadata SET num = 0 WHERE key = ?", - ("current_size_in_mb",), - ) + conn.execute("UPDATE kv_index_num_metadata SET num = 0 WHERE key = ?", ("current_size_in_mb",)) def create_trigger( self,