Optimize table after insertion, update instead of recreating the index
This commit is contained in:
parent
a5e087aa53
commit
d233788400
2 changed files with 13 additions and 6 deletions
|
|
@ -82,6 +82,8 @@ class Store:
|
||||||
self.chunks_table = self.db.open_table("chunks")
|
self.chunks_table = self.db.open_table("chunks")
|
||||||
else:
|
else:
|
||||||
self.chunks_table = self.db.create_table("chunks", schema=self.ChunkRecord)
|
self.chunks_table = self.db.create_table("chunks", schema=self.ChunkRecord)
|
||||||
|
# Create FTS index on the new table
|
||||||
|
self.chunks_table.create_fts_index("content", replace=True)
|
||||||
|
|
||||||
# Create or get settings table
|
# Create or get settings table
|
||||||
if "settings" in existing_tables:
|
if "settings" in existing_tables:
|
||||||
|
|
@ -167,6 +169,9 @@ class Store:
|
||||||
self.ChunkRecord = create_chunk_model(self.embedder._vector_dim)
|
self.ChunkRecord = create_chunk_model(self.embedder._vector_dim)
|
||||||
self.chunks_table = self.db.create_table("chunks", schema=self.ChunkRecord)
|
self.chunks_table = self.db.create_table("chunks", schema=self.ChunkRecord)
|
||||||
|
|
||||||
|
# Create FTS index on the new table
|
||||||
|
self.chunks_table.create_fts_index("content", replace=True)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close the database connection."""
|
"""Close the database connection."""
|
||||||
# LanceDB connections are automatically managed
|
# LanceDB connections are automatically managed
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@ class ChunkRepository:
|
||||||
self.store.chunks_table.add([chunk_record])
|
self.store.chunks_table.add([chunk_record])
|
||||||
|
|
||||||
entity.id = chunk_id
|
entity.id = chunk_id
|
||||||
|
|
||||||
|
# Optimize table after insert to update indexes
|
||||||
|
self.store.chunks_table.optimize()
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
async def get_by_id(self, entity_id: str) -> Chunk | None:
|
async def get_by_id(self, entity_id: str) -> Chunk | None:
|
||||||
|
|
@ -84,6 +87,8 @@ class ChunkRepository:
|
||||||
"vector": embedding,
|
"vector": embedding,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
# Optimize table after update to refresh indexes
|
||||||
|
self.store.chunks_table.optimize()
|
||||||
|
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
|
|
@ -151,6 +156,9 @@ class ChunkRepository:
|
||||||
self.store.chunks_table = self.store.db.create_table(
|
self.store.chunks_table = self.store.db.create_table(
|
||||||
"chunks", schema=self.store.ChunkRecord
|
"chunks", schema=self.store.ChunkRecord
|
||||||
)
|
)
|
||||||
|
# Create FTS index on the new table
|
||||||
|
self.store.chunks_table.create_fts_index("content", replace=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
@ -192,18 +200,12 @@ class ChunkRepository:
|
||||||
return await self._process_search_results(results)
|
return await self._process_search_results(results)
|
||||||
|
|
||||||
elif search_type == "fts":
|
elif search_type == "fts":
|
||||||
# Ensure FTS index exists
|
|
||||||
self._ensure_fts_index()
|
|
||||||
|
|
||||||
results = self.store.chunks_table.search(query, query_type="fts").limit(
|
results = self.store.chunks_table.search(query, query_type="fts").limit(
|
||||||
limit
|
limit
|
||||||
)
|
)
|
||||||
return await self._process_search_results(results)
|
return await self._process_search_results(results)
|
||||||
|
|
||||||
else: # hybrid (default)
|
else: # hybrid (default)
|
||||||
# Ensure FTS index exists for hybrid search
|
|
||||||
self._ensure_fts_index()
|
|
||||||
|
|
||||||
query_embedding = await self.embedder.embed(query)
|
query_embedding = await self.embedder.embed(query)
|
||||||
|
|
||||||
# Create RRF reranker
|
# Create RRF reranker
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue