To ensure vector indexes survive SQLite schema reparses (which occur when DDL is executed on a connection), vectorlite uses a connection-scoped registry pattern.
IndexHandle: A struct representing the stateful core of a vector table. It bundles the NamedVectorSpace and the hnswlib::HierarchicalNSW index together. This bundling is critical because the hnswlib index maintains a pointer into the space. It also stores the original vector_space_str and index_options_str to detect table-name collisions during re-connection.IndexRegistry: A per-connection map that manages the lifetime of IndexHandle objects. Because IndexRegistry is owned by the connection rather than the short-lived VirtualTable object, the indexes persist even when the virtual table is destroyed and recreated during a reparse.
Note: IndexRegistry is not thread-safe, as it relies on SQLite's serialization of access to a single connection.
// Example of the conceptual relationship
// IndexHandle holds the data; IndexRegistry manages the lifetime.
struct IndexHandle {
NamedVectorSpace space;
std::unique_ptr<hnswlib::HierarchicalNSW<float>> index;
bool allow_replace_deleted;
std::string vector_space_str;
std::string index_options_str;
};
class IndexRegistry {
public:
IndexHandle* Find(const RegistryKey& key);
IndexHandle* Insert(const RegistryKey& key, IndexHandle handle);
void Erase(const RegistryKey& key);
};