Create a RedisVectorStore from an existing Redis Search Index.
This method allows you to connect to an already existing index in Redis, which can be useful for continuing work with previously created indexes or for connecting to indexes created outside of this client.
from_existing_index(
cls,
index_name: str,
embedding: Embeddings,
**kwargs: Any = {}
) -> RedisVectorStoreExample:
from langchain_redis import RedisVectorStore
from langchain_openai import OpenAIEmbeddings
from redis import Redis
embeddings = OpenAIEmbeddings()
# Connect to an existing index
vector_store = RedisVectorStore.from_existing_index(
index_name="my-existing-index",
embedding=embeddings,
redis_url="redis://localhost:6379",
vector_query_field="embedding",
content_field="text"
)
# Now you can use the vector_store for similarity search
results = vector_store.similarity_search("AI and machine learning", k=1)
print(results[0].page_content)
Note:
vector_query_field and
content_field respectively.| Name | Type | Description |
|---|---|---|
index_name* | str | Name of the existing index to use. |
embedding* | Embeddings | Embedding function to use for encoding queries. |
**kwargs | Any | Default: {}Additional keyword arguments to pass to Common kwargs include:
|