redis-vl-dotnet
Index Lifecycle
SearchIndex owns the index lifecycle once you have a SearchSchema and a Redis IDatabase.
Constructing an index handle
var schema = SearchSchema.FromYamlFile(schemaPath);
var index = new SearchIndex(database, schema);
This only creates the client-side handle. Redis index creation happens when you call Create or CreateAsync.
Creating an index
The basic flow is:
await index.CreateAsync(new CreateIndexOptions(
overwrite: true,
dropExistingDocuments: true));
CreateIndexOptions supports three behaviors:
-
skipIfExists: returnfalseinstead of failing when the index already exists -
overwrite: drop and recreate the index when it already exists -
dropExistingDocuments: whenoverwritedrops an existing index, also delete matching Redis documents
skipIfExists and overwrite are mutually exclusive.
Inspecting and rediscovering indexes
Use these APIs after creation:
-
ExistsAsync()checks whether the current schema index exists -
InfoAsync()returnsSearchIndexInfo, a key-value view overFT.INFO -
SearchIndex.ListAsync(database)returns all index names asSearchIndexListItem -
SearchIndex.FromExistingAsync(database, indexName)recreates aSearchIndexfrom Redis metadata instead of a local schema definition
The primary example uses both ListAsync and FromExistingAsync so you can verify what Redis created before running document operations.
Clearing versus dropping
Use the right cleanup method for the goal:
-
ClearAsync()deletes indexed documents by prefix but leaves the index in place -
DropAsync()removes the index itself -
DropAsync(deleteDocuments: true)removes both the index and the underlying documents
ClearAsync() is useful in tests or repeatable examples when you want to keep the index definition but wipe data. DropAsync() is the final teardown step when you no longer need the index metadata at all.
Storage-specific document lifecycle
After the index exists, document operations follow the schema storage type:
-
JSON:
LoadJsonAsync,FetchJsonByIdAsync,UpdateJsonByIdAsync,DeleteJsonByIdAsync -
HASH:
LoadHashAsync,FetchHashByIdAsync,UpdateHashByIdAsync,DeleteHashByIdAsync
The JSON example demonstrates create, list, rediscover, clear, and drop flows. The HASH vector example shows the same lifecycle with hash-backed documents.
Example reference
Primary example:
-
/examples/JsonStorageExample
Supporting HASH example:
-
/examples/VectorSearchExample