{
  "id": "searchindex",
  "title": "Search Index Classes",
  "url": "https://redis.io/docs/latest/develop/ai/redisvl/0.9.1/api/searchindex/",
  "summary": "",
  "content": "\n\n| Class                                     | Description                                                                                  |\n|-------------------------------------------|----------------------------------------------------------------------------------------------|\n| [SearchIndex](#searchindex-api)           | Primary class to write, read, and search across data structures in Redis.                    |\n| [AsyncSearchIndex](#asyncsearchindex-api) | Async version of the SearchIndex to write, read, and search across data structures in Redis. |\n\n\u003ca id=\"searchindex-api\"\u003e\u003c/a\u003e\n\n## SearchIndex\n\n### `class SearchIndex(schema, redis_client=None, redis_url=None, connection_kwargs=None, validate_on_load=False, **kwargs)`\n\nA search index class for interacting with Redis as a vector database.\n\nThe SearchIndex is instantiated with a reference to a Redis database and an\nIndexSchema (YAML path or dictionary object) that describes the various\nsettings and field configurations.\n\n```python\nfrom redisvl.index import SearchIndex\n\n# initialize the index object with schema from file\nindex = SearchIndex.from_yaml(\n    \"schemas/schema.yaml\",\n    redis_url=\"redis://localhost:6379\",\n    validate_on_load=True\n)\n\n# create the index\nindex.create(overwrite=True, drop=False)\n\n# data is an iterable of dictionaries\nindex.load(data)\n\n# delete index and data\nindex.delete(drop=True)\n```\n\nInitialize the RedisVL search index with a schema, Redis client\n(or URL string with other connection args), connection_args, and other\nkwargs.\n\n* **Parameters:**\n  * **schema** ([*IndexSchema*]()) – Index schema object.\n  * **redis_client** (*Optional* *[* *Redis* *]*) – An\n    instantiated redis client.\n  * **redis_url** (*Optional* *[* *str* *]*) – The URL of the Redis server to\n    connect to.\n  * **connection_kwargs** (*Dict* *[* *str* *,* *Any* *]* *,* *optional*) – Redis client connection\n    args.\n  * **validate_on_load** (*bool* *,* *optional*) – Whether to validate data against schema\n    when loading. Defaults to False.\n\n#### `aggregate(*args, **kwargs)`\n\nPerform an aggregation operation against the index.\n\nWrapper around the aggregation API that adds the index name\nto the query and passes along the rest of the arguments\nto the redis-py ft().aggregate() method.\n\n* **Returns:**\n  Raw Redis aggregation results.\n* **Return type:**\n  Result\n\n#### `batch_query(queries, batch_size=10)`\n\nExecute a batch of queries and process results.\n\n* **Parameters:**\n  * **queries** (*Sequence* *[* *BaseQuery* *]*)\n  * **batch_size** (*int*)\n* **Return type:**\n  *List*[*List*[*Dict*[str, *Any*]]]\n\n#### `batch_search(queries, batch_size=10)`\n\nPerform a search against the index for multiple queries.\n\nThis method takes a list of queries and optionally query params and\nreturns a list of Result objects for each query. Results are\nreturned in the same order as the queries.\n\nNOTE: Cluster users may need to incorporate hash tags into their query\nto avoid cross-slot operations.\n\n* **Parameters:**\n  * **queries** (*List* *[* *SearchParams* *]*) – The queries to search for.\n  * **batch_size** (*int* *,* *optional*) – The number of queries to search for at a time.\n    Defaults to 10.\n* **Returns:**\n  The search results for each query.\n* **Return type:**\n  List[Result]\n\n#### `clear()`\n\nClear all keys in Redis associated with the index, leaving the index\navailable and in-place for future insertions or updates.\n\nNOTE: This method requires custom behavior for Redis Cluster because\nhere, we can’t easily give control of the keys we’re clearing to the\nuser so they can separate them based on hash tag.\n\n* **Returns:**\n  Count of records deleted from Redis.\n* **Return type:**\n  int\n\n#### `connect(redis_url=None, **kwargs)`\n\nConnect to a Redis instance using the provided redis_url, falling\nback to the REDIS_URL environment variable (if available).\n\nNote: Additional keyword arguments (\\*\\*kwargs) can be used to provide\nextra options specific to the Redis connection.\n\n* **Parameters:**\n  **redis_url** (*Optional* *[* *str* *]* *,* *optional*) – The URL of the Redis server to\n  connect to.\n* **Raises:**\n  * **redis.exceptions.ConnectionError** – If the connection to the Redis\n        server fails.\n  * **ValueError** – If the Redis URL is not provided nor accessible\n        through the REDIS_URL environment variable.\n  * **ModuleNotFoundError** – If required Redis modules are not installed.\n\n#### `create(overwrite=False, drop=False)`\n\nCreate an index in Redis with the current schema and properties.\n\n* **Parameters:**\n  * **overwrite** (*bool* *,* *optional*) – Whether to overwrite the index if it\n    already exists. Defaults to False.\n  * **drop** (*bool* *,* *optional*) – Whether to drop all keys associated with the\n    index in the case of overwriting. Defaults to False.\n* **Raises:**\n  * **RuntimeError** – If the index already exists and ‘overwrite’ is False.\n  * **ValueError** – If no fields are defined for the index.\n* **Return type:**\n  None\n\n```python\n# create an index in Redis; only if one does not exist with given name\nindex.create()\n\n# overwrite an index in Redis without dropping associated data\nindex.create(overwrite=True)\n\n# overwrite an index in Redis; drop associated data (clean slate)\nindex.create(overwrite=True, drop=True)\n```\n\n#### `delete(drop=True)`\n\nDelete the search index while optionally dropping all keys associated\nwith the index.\n\n* **Parameters:**\n  **drop** (*bool* *,* *optional*) – Delete the key / documents pairs in the\n  index. Defaults to True.\n* **Raises:**\n  **redis.exceptions.ResponseError** – If the index does not exist.\n\n#### `disconnect()`\n\nDisconnect from the Redis database.\n\n#### `drop_documents(ids)`\n\nRemove documents from the index by their document IDs.\n\nThis method converts document IDs to Redis keys automatically by applying\nthe index’s key prefix and separator configuration.\n\nNOTE: Cluster users will need to incorporate hash tags into their\ndocument IDs and only call this method with documents from a single hash\ntag at a time.\n\n* **Parameters:**\n  **ids** (*Union* *[* *str* *,* *List* *[* *str* *]* *]*) – The document ID or IDs to remove from the index.\n* **Returns:**\n  Count of documents deleted from Redis.\n* **Return type:**\n  int\n\n#### `drop_keys(keys)`\n\nRemove a specific entry or entries from the index by it’s key ID.\n\n* **Parameters:**\n  **keys** (*Union* *[* *str* *,* *List* *[* *str* *]* *]*) – The document ID or IDs to remove from the index.\n* **Returns:**\n  Count of records deleted from Redis.\n* **Return type:**\n  int\n\n#### `exists()`\n\nCheck if the index exists in Redis.\n\n* **Returns:**\n  True if the index exists, False otherwise.\n* **Return type:**\n  bool\n\n#### `expire_keys(keys, ttl)`\n\nSet the expiration time for a specific entry or entries in Redis.\n\n* **Parameters:**\n  * **keys** (*Union* *[* *str* *,* *List* *[* *str* *]* *]*) – The entry ID or IDs to set the expiration for.\n  * **ttl** (*int*) – The time-to-live in seconds.\n* **Return type:**\n  int | *List*[int]\n\n#### `fetch(id)`\n\nFetch an object from Redis by id.\n\nThe id is typically either a unique identifier,\nor derived from some domain-specific metadata combination\n(like a document id or chunk id).\n\n* **Parameters:**\n  **id** (*str*) – The specified unique identifier for a particular\n  document indexed in Redis.\n* **Returns:**\n  The fetched object.\n* **Return type:**\n  Dict[str, Any]\n\n#### `classmethod from_dict(schema_dict, **kwargs)`\n\nCreate a SearchIndex from a dictionary.\n\n* **Parameters:**\n  **schema_dict** (*Dict* *[* *str* *,* *Any* *]*) – A dictionary containing the schema.\n* **Returns:**\n  A RedisVL SearchIndex object.\n* **Return type:**\n  [SearchIndex](#searchindex)\n\n```python\nfrom redisvl.index import SearchIndex\n\nindex = SearchIndex.from_dict({\n    \"index\": {\n        \"name\": \"my-index\",\n        \"prefix\": \"rvl\",\n        \"storage_type\": \"hash\",\n    },\n    \"fields\": [\n        {\"name\": \"doc-id\", \"type\": \"tag\"}\n    ]\n}, redis_url=\"redis://localhost:6379\")\n```\n\n#### `classmethod from_existing(name, redis_client=None, redis_url=None, **kwargs)`\n\nInitialize from an existing search index in Redis by index name.\n\n* **Parameters:**\n  * **name** (*str*) – Name of the search index in Redis.\n  * **redis_client** (*Optional* *[* *Redis* *]*) – An\n    instantiated redis client.\n  * **redis_url** (*Optional* *[* *str* *]*) – The URL of the Redis server to\n    connect to.\n* **Raises:**\n  **ValueError** – If redis_url or redis_client is not provided.\n\n#### `classmethod from_yaml(schema_path, **kwargs)`\n\nCreate a SearchIndex from a YAML schema file.\n\n* **Parameters:**\n  **schema_path** (*str*) – Path to the YAML schema file.\n* **Returns:**\n  A RedisVL SearchIndex object.\n* **Return type:**\n  [SearchIndex](#searchindex)\n\n```python\nfrom redisvl.index import SearchIndex\n\nindex = SearchIndex.from_yaml(\"schemas/schema.yaml\", redis_url=\"redis://localhost:6379\")\n```\n\n#### `info(name=None)`\n\nGet information about the index.\n\n* **Parameters:**\n  **name** (*str* *,* *optional*) – Index name to fetch info about.\n  Defaults to None.\n* **Returns:**\n  A dictionary containing the information about the index.\n* **Return type:**\n  dict\n\n#### `key(id)`\n\nConstruct a redis key as a combination of an index key prefix (optional)\nand specified id.\n\nThe id is typically either a unique identifier, or\nderived from some domain-specific metadata combination (like a document\nid or chunk id).\n\n* **Parameters:**\n  **id** (*str*) – The specified unique identifier for a particular\n  document indexed in Redis.\n* **Returns:**\n  The full Redis key including key prefix and value as a string.\n* **Return type:**\n  str\n\n#### `listall()`\n\nList all search indices in Redis database.\n\n* **Returns:**\n  The list of indices in the database.\n* **Return type:**\n  List[str]\n\n#### `load(data, id_field=None, keys=None, ttl=None, preprocess=None, batch_size=None)`\n\nLoad objects to the Redis database. Returns the list of keys loaded\nto Redis.\n\nRedisVL automatically handles constructing the object keys, batching,\noptional preprocessing steps, and setting optional expiration\n(TTL policies) on keys.\n\n* **Parameters:**\n  * **data** (*Iterable* *[* *Any* *]*) – An iterable of objects to store.\n  * **id_field** (*Optional* *[* *str* *]* *,* *optional*) – Specified field used as the id\n    portion of the redis key (after the prefix) for each\n    object. Defaults to None.\n  * **keys** (*Optional* *[* *Iterable* *[* *str* *]* *]* *,* *optional*) – Optional iterable of keys.\n    Must match the length of objects if provided. Defaults to None.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – Time-to-live in seconds for each key.\n    Defaults to None.\n  * **preprocess** (*Optional* *[* *Callable* *]* *,* *optional*) – A function to preprocess\n    objects before storage. Defaults to None.\n  * **batch_size** (*Optional* *[* *int* *]* *,* *optional*) – Number of objects to write in\n    a single Redis pipeline execution. Defaults to class’s\n    default batch size.\n* **Returns:**\n  List of keys loaded to Redis.\n* **Return type:**\n  List[str]\n* **Raises:**\n  * **SchemaValidationError** – If validation fails when validate_on_load is enabled.\n  * **RedisVLError** – If there’s an error loading data to Redis.\n\n#### `paginate(query, page_size=30)`\n\nExecute a given query against the index and return results in\npaginated batches.\n\nThis method accepts a RedisVL query instance, enabling pagination of\nresults which allows for subsequent processing over each batch with a\ngenerator.\n\n* **Parameters:**\n  * **query** (*BaseQuery*) – The search query to be executed.\n  * **page_size** (*int* *,* *optional*) – The number of results to return in each\n    batch. Defaults to 30.\n* **Yields:**\n  A generator yielding batches of search results.\n* **Raises:**\n  * **TypeError** – If the page_size argument is not of type int.\n  * **ValueError** – If the page_size argument is less than or equal to zero.\n* **Return type:**\n  *Generator*\n\n```python\n# Iterate over paginated search results in batches of 10\nfor result_batch in index.paginate(query, page_size=10):\n    # Process each batch of results\n    pass\n```\n\n#### `NOTE`\nThe page_size parameter controls the number of items each result\nbatch contains. Adjust this value based on performance\nconsiderations and the expected volume of search results.\n\n#### `query(query)`\n\nExecute a query on the index.\n\nThis method takes a BaseQuery or AggregationQuery object directly, and\nhandles post-processing of the search.\n\n* **Parameters:**\n  **query** (*Union* *[* *BaseQuery* *,* *AggregateQuery* *]*) – The query to run.\n* **Returns:**\n  A list of search results.\n* **Return type:**\n  List[Result]\n\n```python\nfrom redisvl.query import VectorQuery\n\nquery = VectorQuery(\n    vector=[0.16, -0.34, 0.98, 0.23],\n    vector_field_name=\"embedding\",\n    num_results=3\n)\n\nresults = index.query(query)\n```\n\n#### `search(*args, **kwargs)`\n\nPerform a search against the index.\n\nWrapper around the search API that adds the index name\nto the query and passes along the rest of the arguments\nto the redis-py ft().search() method.\n\n* **Returns:**\n  Raw Redis search results.\n* **Return type:**\n  Result\n\n#### `set_client(redis_client, **kwargs)`\n\nManually set the Redis client to use with the search index.\n\nThis method configures the search index to use a specific Redis or\nAsync Redis client. It is useful for cases where an external,\ncustom-configured client is preferred instead of creating a new one.\n\n* **Parameters:**\n  **redis_client** (*Redis*) – A Redis or Async Redis\n  client instance to be used for the connection.\n* **Raises:**\n  **TypeError** – If the provided client is not valid.\n\n#### `property client: Redis | RedisCluster | None`\n\nThe underlying redis-py client object.\n\n#### `property key_separator: str`\n\nThe optional separator between a defined prefix and key value in\nforming a Redis key.\n\n#### `property name: str`\n\nThe name of the Redis search index.\n\n#### `property prefix: str`\n\nThe optional key prefix that comes before a unique key value in\nforming a Redis key. If multiple prefixes are configured, returns the\nfirst one.\n\n#### `property storage_type: StorageType`\n\nThe underlying storage type for the search index; either\nhash or json.\n\n\u003ca id=\"asyncsearchindex-api\"\u003e\u003c/a\u003e\n\n## AsyncSearchIndex\n\n### `class AsyncSearchIndex(schema, *, redis_url=None, redis_client=None, connection_kwargs=None, validate_on_load=False, **kwargs)`\n\nA search index class for interacting with Redis as a vector database in\nasync-mode.\n\nThe AsyncSearchIndex is instantiated with a reference to a Redis database\nand an IndexSchema (YAML path or dictionary object) that describes the\nvarious settings and field configurations.\n\n```python\nfrom redisvl.index import AsyncSearchIndex\n\n# initialize the index object with schema from file\nindex = AsyncSearchIndex.from_yaml(\n    \"schemas/schema.yaml\",\n    redis_url=\"redis://localhost:6379\",\n    validate_on_load=True\n)\n\n# create the index\nawait index.create(overwrite=True, drop=False)\n\n# data is an iterable of dictionaries\nawait index.load(data)\n\n# delete index and data\nawait index.delete(drop=True)\n```\n\nInitialize the RedisVL async search index with a schema.\n\n* **Parameters:**\n  * **schema** ([*IndexSchema*]()) – Index schema object.\n  * **redis_url** (*Optional* *[* *str* *]* *,* *optional*) – The URL of the Redis server to\n    connect to.\n  * **redis_client** (*Optional* *[* *AsyncRedis* *]*) – An\n    instantiated redis client.\n  * **connection_kwargs** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – Redis client connection\n    args.\n  * **validate_on_load** (*bool* *,* *optional*) – Whether to validate data against schema\n    when loading. Defaults to False.\n\n#### `async aggregate(*args, **kwargs)`\n\nPerform an aggregation operation against the index.\n\nWrapper around the aggregation API that adds the index name\nto the query and passes along the rest of the arguments\nto the redis-py ft().aggregate() method.\n\n* **Returns:**\n  Raw Redis aggregation results.\n* **Return type:**\n  Result\n\n#### `async batch_query(queries, batch_size=10)`\n\nAsynchronously execute a batch of queries and process results.\n\n* **Parameters:**\n  * **queries** (*List* *[* *BaseQuery* *]*)\n  * **batch_size** (*int*)\n* **Return type:**\n  *List*[*List*[*Dict*[str, *Any*]]]\n\n#### `async batch_search(queries, batch_size=10)`\n\nAsynchronously execute a batch of search queries.\n\nThis method takes a list of search queries and executes them in batches\nto improve performance when dealing with multiple queries.\n\nNOTE: Cluster users may need to incorporate hash tags into their query\nto avoid cross-slot operations.\n\n* **Parameters:**\n  * **queries** (*List* *[* *SearchParams* *]*) – A list of search queries to execute.\n    Each query can be either a string or a tuple of (query, params).\n  * **batch_size** (*int* *,* *optional*) – The number of queries to execute in each\n    batch. Defaults to 10.\n* **Returns:**\n  A list of search results corresponding to each query.\n* **Return type:**\n  List[Result]\n\n```python\nqueries = [\n    \"hello world\",\n    (\"goodbye world\", {\"num_results\": 5}),\n]\n\nresults = await index.batch_search(queries)\n```\n\n#### `async clear()`\n\nClear all keys in Redis associated with the index, leaving the index\navailable and in-place for future insertions or updates.\n\nNOTE: This method requires custom behavior for Redis Cluster because here,\nwe can’t easily give control of the keys we’re clearing to the user so they\ncan separate them based on hash tag.\n\n* **Returns:**\n  Count of records deleted from Redis.\n* **Return type:**\n  int\n\n#### `connect(redis_url=None, **kwargs)`\n\n[DEPRECATED] Connect to a Redis instance. Use connection parameters in \\_\\_init_\\_.\n\n* **Parameters:**\n  **redis_url** (*str* *|* *None*)\n\n#### `async create(overwrite=False, drop=False)`\n\nAsynchronously create an index in Redis with the current schema\n: and properties.\n\n* **Parameters:**\n  * **overwrite** (*bool* *,* *optional*) – Whether to overwrite the index if it\n    already exists. Defaults to False.\n  * **drop** (*bool* *,* *optional*) – Whether to drop all keys associated with the\n    index in the case of overwriting. Defaults to False.\n* **Raises:**\n  * **RuntimeError** – If the index already exists and ‘overwrite’ is False.\n  * **ValueError** – If no fields are defined for the index.\n* **Return type:**\n  None\n\n```python\n# create an index in Redis; only if one does not exist with given name\nawait index.create()\n\n# overwrite an index in Redis without dropping associated data\nawait index.create(overwrite=True)\n\n# overwrite an index in Redis; drop associated data (clean slate)\nawait index.create(overwrite=True, drop=True)\n```\n\n#### `async delete(drop=True)`\n\nDelete the search index.\n\n* **Parameters:**\n  **drop** (*bool* *,* *optional*) – Delete the documents in the index.\n  Defaults to True.\n* **Raises:**\n  **redis.exceptions.ResponseError** – If the index does not exist.\n\n#### `async disconnect()`\n\nDisconnect from the Redis database.\n\n#### `async drop_documents(ids)`\n\nRemove documents from the index by their document IDs.\n\nThis method converts document IDs to Redis keys automatically by applying\nthe index’s key prefix and separator configuration.\n\nNOTE: Cluster users will need to incorporate hash tags into their\ndocument IDs and only call this method with documents from a single hash\ntag at a time.\n\n* **Parameters:**\n  **ids** (*Union* *[* *str* *,* *List* *[* *str* *]* *]*) – The document ID or IDs to remove from the index.\n* **Returns:**\n  Count of documents deleted from Redis.\n* **Return type:**\n  int\n\n#### `async drop_keys(keys)`\n\nRemove a specific entry or entries from the index by it’s key ID.\n\n* **Parameters:**\n  **keys** (*Union* *[* *str* *,* *List* *[* *str* *]* *]*) – The document ID or IDs to remove from the index.\n* **Returns:**\n  Count of records deleted from Redis.\n* **Return type:**\n  int\n\n#### `async exists()`\n\nCheck if the index exists in Redis.\n\n* **Returns:**\n  True if the index exists, False otherwise.\n* **Return type:**\n  bool\n\n#### `async expire_keys(keys, ttl)`\n\nSet the expiration time for a specific entry or entries in Redis.\n\n* **Parameters:**\n  * **keys** (*Union* *[* *str* *,* *List* *[* *str* *]* *]*) – The entry ID or IDs to set the expiration for.\n  * **ttl** (*int*) – The time-to-live in seconds.\n* **Return type:**\n  int | *List*[int]\n\n#### `async fetch(id)`\n\nAsynchronously etch an object from Redis by id. The id is typically\neither a unique identifier, or derived from some domain-specific\nmetadata combination (like a document id or chunk id).\n\n* **Parameters:**\n  **id** (*str*) – The specified unique identifier for a particular\n  document indexed in Redis.\n* **Returns:**\n  The fetched object.\n* **Return type:**\n  Dict[str, Any]\n\n#### `classmethod from_dict(schema_dict, **kwargs)`\n\nCreate a SearchIndex from a dictionary.\n\n* **Parameters:**\n  **schema_dict** (*Dict* *[* *str* *,* *Any* *]*) – A dictionary containing the schema.\n* **Returns:**\n  A RedisVL SearchIndex object.\n* **Return type:**\n  [SearchIndex](#searchindex)\n\n```python\nfrom redisvl.index import SearchIndex\n\nindex = SearchIndex.from_dict({\n    \"index\": {\n        \"name\": \"my-index\",\n        \"prefix\": \"rvl\",\n        \"storage_type\": \"hash\",\n    },\n    \"fields\": [\n        {\"name\": \"doc-id\", \"type\": \"tag\"}\n    ]\n}, redis_url=\"redis://localhost:6379\")\n```\n\n#### `async classmethod* from_existing(name, redis_client=None, redis_url=None, **kwargs)`\n\nInitialize from an existing search index in Redis by index name.\n\n* **Parameters:**\n  * **name** (*str*) – Name of the search index in Redis.\n  * **redis_client** (*Optional* *[* *Redis* *]*) – An\n    instantiated redis client.\n  * **redis_url** (*Optional* *[* *str* *]*) – The URL of the Redis server to\n    connect to.\n\n#### `classmethod from_yaml(schema_path, **kwargs)`\n\nCreate a SearchIndex from a YAML schema file.\n\n* **Parameters:**\n  **schema_path** (*str*) – Path to the YAML schema file.\n* **Returns:**\n  A RedisVL SearchIndex object.\n* **Return type:**\n  [SearchIndex](#searchindex)\n\n```python\nfrom redisvl.index import SearchIndex\n\nindex = SearchIndex.from_yaml(\"schemas/schema.yaml\", redis_url=\"redis://localhost:6379\")\n```\n\n#### `async info(name=None)`\n\nGet information about the index.\n\n* **Parameters:**\n  **name** (*str* *,* *optional*) – Index name to fetch info about.\n  Defaults to None.\n* **Returns:**\n  A dictionary containing the information about the index.\n* **Return type:**\n  dict\n\n#### `key(id)`\n\nConstruct a redis key as a combination of an index key prefix (optional)\nand specified id.\n\nThe id is typically either a unique identifier, or\nderived from some domain-specific metadata combination (like a document\nid or chunk id).\n\n* **Parameters:**\n  **id** (*str*) – The specified unique identifier for a particular\n  document indexed in Redis.\n* **Returns:**\n  The full Redis key including key prefix and value as a string.\n* **Return type:**\n  str\n\n#### `async listall()`\n\nList all search indices in Redis database.\n\n* **Returns:**\n  The list of indices in the database.\n* **Return type:**\n  List[str]\n\n#### `load(data, id_field=None, keys=None, ttl=None, preprocess=None, concurrency=None, batch_size=None)`\n\nAsynchronously load objects to Redis. Returns the list of keys loaded\nto Redis.\n\nRedisVL automatically handles constructing the object keys, batching,\noptional preprocessing steps, and setting optional expiration\n(TTL policies) on keys.\n\n* **Parameters:**\n  * **data** (*Iterable* *[* *Any* *]*) – An iterable of objects to store.\n  * **id_field** (*Optional* *[* *str* *]* *,* *optional*) – Specified field used as the id\n    portion of the redis key (after the prefix) for each\n    object. Defaults to None.\n  * **keys** (*Optional* *[* *Iterable* *[* *str* *]* *]* *,* *optional*) – Optional iterable of keys.\n    Must match the length of objects if provided. Defaults to None.\n  * **ttl** (*Optional* *[* *int* *]* *,* *optional*) – Time-to-live in seconds for each key.\n    Defaults to None.\n  * **preprocess** (*Optional* *[* *Callable* *]* *,* *optional*) – A function to\n    preprocess objects before storage. Defaults to None.\n  * **batch_size** (*Optional* *[* *int* *]* *,* *optional*) – Number of objects to write in\n    a single Redis pipeline execution. Defaults to class’s\n    default batch size.\n  * **concurrency** (*int* *|* *None*)\n* **Returns:**\n  List of keys loaded to Redis.\n* **Return type:**\n  List[str]\n* **Raises:**\n  * **SchemaValidationError** – If validation fails when validate_on_load is enabled.\n  * **RedisVLError** – If there’s an error loading data to Redis.\n\n```python\ndata = [{\"test\": \"foo\"}, {\"test\": \"bar\"}]\n\n# simple case\nkeys = await index.load(data)\n\n# set 360 second ttl policy on data\nkeys = await index.load(data, ttl=360)\n\n# load data with predefined keys\nkeys = await index.load(data, keys=[\"rvl:foo\", \"rvl:bar\"])\n\n# load data with preprocessing step\ndef add_field(d):\n    d[\"new_field\"] = 123\n    return d\nkeys = await index.load(data, preprocess=add_field)\n```\n\n#### `async paginate(query, page_size=30)`\n\nExecute a given query against the index and return results in\npaginated batches.\n\nThis method accepts a RedisVL query instance, enabling async pagination\nof results which allows for subsequent processing over each batch with a\ngenerator.\n\n* **Parameters:**\n  * **query** (*BaseQuery*) – The search query to be executed.\n  * **page_size** (*int* *,* *optional*) – The number of results to return in each\n    batch. Defaults to 30.\n* **Yields:**\n  An async generator yielding batches of search results.\n* **Raises:**\n  * **TypeError** – If the page_size argument is not of type int.\n  * **ValueError** – If the page_size argument is less than or equal to zero.\n* **Return type:**\n  *AsyncGenerator*\n\n```python\n# Iterate over paginated search results in batches of 10\nasync for result_batch in index.paginate(query, page_size=10):\n    # Process each batch of results\n    pass\n```\n\n#### `NOTE`\nThe page_size parameter controls the number of items each result\nbatch contains. Adjust this value based on performance\nconsiderations and the expected volume of search results.\n\n#### `async query(query)`\n\nAsynchronously execute a query on the index.\n\nThis method takes a BaseQuery or AggregationQuery object directly, runs\nthe search, and handles post-processing of the search.\n\n* **Parameters:**\n  **query** (*Union* *[* *BaseQuery* *,* *AggregateQuery* *]*) – The query to run.\n* **Returns:**\n  A list of search results.\n* **Return type:**\n  List[Result]\n\n```python\nfrom redisvl.query import VectorQuery\n\nquery = VectorQuery(\n    vector=[0.16, -0.34, 0.98, 0.23],\n    vector_field_name=\"embedding\",\n    num_results=3\n)\n\nresults = await index.query(query)\n```\n\n#### `async search(*args, **kwargs)`\n\nPerform an async search against the index.\n\nWrapper around the search API that adds the index name\nto the query and passes along the rest of the arguments\nto the redis-py ft().search() method.\n\n* **Returns:**\n  Raw Redis search results.\n* **Return type:**\n  Result\n\n#### `set_client(redis_client)`\n\n[DEPRECATED] Manually set the Redis client to use with the search index.\nThis method is deprecated; please provide connection parameters in \\_\\_init_\\_.\n\n* **Parameters:**\n  **redis_client** (*Redis* *|* *RedisCluster* *|* *Redis* *|* *RedisCluster*)\n\n#### `property client: Redis | RedisCluster | None`\n\nThe underlying redis-py client object.\n\n#### `property key_separator: str`\n\nThe optional separator between a defined prefix and key value in\nforming a Redis key.\n\n#### `property name: str`\n\nThe name of the Redis search index.\n\n#### `property prefix: str`\n\nThe optional key prefix that comes before a unique key value in\nforming a Redis key. If multiple prefixes are configured, returns the\nfirst one.\n\n#### `property storage_type: StorageType`\n\nThe underlying storage type for the search index; either\nhash or json.\n",
  "tags": [],
  "last_updated": "2026-04-01T08:10:08-05:00"
}

