이 페이지에서는 해시에 벡터를 저장하는 방법을 설명합니다. 해시를 사용하면 벡터를 Redis에 효율적으로 저장할 수 있습니다.
데이터 직렬화
벡터를 Redis 해시에 저장하기 전에 벡터를 Redis가 이해할 수 있는 형식으로 변환해야 합니다. 이렇게 하려면 크기가 데이터 유형의 바이트 크기(예: FLOAT32의 경우 4)에 벡터의 차원 수를 곱한 값과 동일한 바이너리 blob으로의 벡터 직렬화가 필요합니다. 숫자 벡터에 널리 사용되는 옵션은 Python NumPy 라이브러리입니다.
Redis에 연결
벡터를 해시에 저장하기 전에 redis-py와 같은 클라이언트를 사용하여 Redis 인스턴스에 대한 연결을 설정하세요.
해시에 벡터 저장
Redis 해시는 키-값 쌍이 있는 사전과 같습니다. Redis HSET 명령어를 사용하여 직렬화된 벡터를 저장합니다.
import numpy as np
import redis
# Sample vector
vector = np.array([1.2, 3.5, -0.8], dtype=np.float32) # 3-dimensional vector
# Serialize to a binary blob
serialized_vector = vector.tobytes()
redis_client = redis.Redis(host='your_redis_host', port=6379)
redis_client.hset('vector_storage', 'vector_key', serialized_vector) # 'vector_key' is a unique identifier
색인을 성공적으로 생성하려면 벡터 데이터가 색인 스키마에 설정된 측정기준과 데이터 유형을 준수해야 합니다.
색인 백필
색인 백필은 다음 시나리오 중 하나에서 발생할 수 있습니다.
색인이 생성되면 백필 절차에서 Redis 키스페이스를 통해 색인 필터 기준을 충족하는 항목을 스캔합니다.
벡터 색인과 해당 데이터는 RDB 스냅샷에 유지됩니다. RDB 파일이 로드되면 자동 색인 백필 프로세스가 트리거됩니다. 이 프로세스는 RDB 스냅샷이 생성된 후에 새로운 항목이나 수정된 항목을 적극적으로 감지하고 색인에 통합하므로 색인 무결성이 유지되고 현재 결과가 보장됩니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Indexing vectors\n\nThis page explains how to store vectors in hashes. Hashes provide an efficient way to store vectors in Redis.\n\nData serialization\n------------------\n\nBefore storing vectors in a hash data type, vectors need to be converted into a format that Memorystore for Redis understands. It requires vector serialization into binary blobs where the size equals the data type's byte size (e.g., 4 for FLOAT32) multiplied by the vector's number of dimensions. A popular choice for numerical vectors is the Python [NumPy library](https://numpy.org/):\n\nConnect to Redis\n----------------\n\nBefore storing the vector in a hash, establish a connection to your Memorystore for Redis instance using a OSS Redis compatible client like [redis-py](https://github.com/redis/redis-py):\n\nStore the vector in a hash\n--------------------------\n\nHashes are like dictionaries, with key-value pairs. Use the `HSET` command to store your serialized vector: \n\n```\nimport numpy as np\nimport redis\n\n# Sample vector\nvector = np.array([1.2, 3.5, -0.8], dtype=np.float32) # 3-dimensional vector\n\n# Serialize to a binary blob\nserialized_vector = vector.tobytes()\n\nredis_client = redis.Redis(host='your_redis_host', port=6379)\n\nredis_client.hset('vector_storage', 'vector_key', serialized_vector) # 'vector_key' is a unique identifier\n```\n\n- For successful indexing, your vector data must adhere to the dimensions and data type set in the index schema.\n\nBackfilling Indexes\n-------------------\n\nBackfilling indexes may occur in one of the following scenarios:\n\n- Once an index is created, the backfilling procedure scans through keyspace for entries that meet the index filter criteria.\n- Vector indexes and their data are persisted in [RDB snapshots](/memorystore/docs/redis/about-rdb-snapshots). When an RDB file is loaded, an automatic index backfilling process is triggered. This process actively detects and integrates any new or modified entries into the index since the RDB snapshot was created, maintaining index integrity and ensuring current results."]]