@@ -153,7 +153,8 @@ def __init__(
153153 embedder : t .Optional [Embedder ] = None ,
154154 sync : str = "strict" ,
155155 max_entries : t .Optional [int ] = None ,
156- index_mode : str = "exact" ,
156+ max_bytes : t .Optional [int ] = None ,
157+ index_mode : t .Union [str , t .Dict [str , t .Any ]] = "exact" ,
157158 _recorder : t .Optional [ReplayWriter ] = None ,
158159 ):
159160 self ._embedder = embedder
@@ -164,6 +165,7 @@ def __init__(
164165 dimension = dimension ,
165166 sync = sync ,
166167 max_entries = max_entries ,
168+ max_bytes = max_bytes ,
167169 index_mode = index_mode ,
168170 )
169171 except Exception as e :
@@ -180,7 +182,8 @@ def open(
180182 embedder : t .Optional [Embedder ] = None ,
181183 sync : str = "strict" ,
182184 max_entries : t .Optional [int ] = None ,
183- index_mode : str = "exact" ,
185+ max_bytes : t .Optional [int ] = None ,
186+ index_mode : t .Union [str , t .Dict [str , t .Any ]] = "exact" ,
184187 record : t .Optional [str ] = None ,
185188 ) -> "CortexaDB" :
186189 """
@@ -196,6 +199,8 @@ def open(
196199 inferred from ``embedder.dimension`` automatically.
197200 sync: Write durability policy: ``"strict"`` (default),
198201 ``"async"``, or ``"batch"``.
202+ max_entries: Optional entry-count limit for automatic eviction.
203+ max_bytes: Optional byte-size limit for automatic eviction.
199204 index_mode: Search index mode: ``"exact"`` (default) or ``"hnsw"``.
200205 Can also be a dict with HNSW parameters.
201206 record: Optional path to a replay log file. When set, every write
@@ -225,6 +230,7 @@ def open(
225230 embedder = embedder ,
226231 sync = sync ,
227232 max_entries = max_entries ,
233+ max_bytes = max_bytes ,
228234 index_mode = index_mode ,
229235 _recorder = recorder ,
230236 )
@@ -311,6 +317,11 @@ def replay(
311317 db ._inner .checkpoint ()
312318 except Exception :
313319 pass # non-fatal on fresh DB
320+ elif op == "compact" :
321+ try :
322+ db ._inner .compact ()
323+ except Exception :
324+ pass # non-fatal on fresh DB
314325
315326 return db
316327
@@ -680,20 +691,23 @@ def export_replay(self, log_path: str) -> None:
680691 while found < target and checked < target * 4 :
681692 try :
682693 mem = self ._inner .get (candidate )
683- # Retrieve the stored embedding via ask with dimension probe
684- hits = self ._inner .ask_in_namespace (
685- namespace = mem .namespace ,
686- embedding = mem .embedding
687- if hasattr (mem , "embedding" )
688- else [0.0 ] * dim ,
689- top_k = 1 ,
690- )
694+ embedding = getattr (mem , "embedding" , None )
695+ if not embedding :
696+ candidate += 1
697+ checked += 1
698+ continue
699+ content = getattr (mem , "content" , b"" )
700+ if isinstance (content , bytes ):
701+ text = content .decode ("utf-8" , errors = "replace" )
702+ else :
703+ text = str (content )
704+ metadata = dict (mem .metadata ) if hasattr (mem , "metadata" ) else None
691705 writer .record_remember (
692706 id = mem .id ,
693- text = mem . content if hasattr ( mem , "content" ) else "" ,
694- embedding = mem . embedding if hasattr ( mem , "embedding" ) else [] ,
707+ text = text ,
708+ embedding = embedding ,
695709 namespace = mem .namespace ,
696- metadata = None ,
710+ metadata = metadata ,
697711 )
698712 found += 1
699713 except Exception :
0 commit comments