Add text documents to the vector store.
Example:
from langchain_redis import RedisVectorStore
from langchain_openai import OpenAIEmbeddings
vector_store = RedisVectorStore(
index_name="langchain-demo",
embedding=OpenAIEmbeddings(),
redis_url="redis://localhost:6379",
)
texts = [
"The quick brown fox jumps over the lazy dog",
"Hello world",
"Machine learning is fascinating"
]
metadatas = [
{"source": "book", "page": 1},
{"source": "greeting", "language": "english"},
{"source": "article", "topic": "AI"}
]
ids = vector_store.add_texts(
texts=texts,
metadatas=metadatas,
batch_size=2
)
print(f"Added documents with ids: {ids}")
Note:
metadatas is provided, it must have the same length as texts.keys is provided, it must have the same length as texts.batch_size parameter can be used to control the number of
documents added in each batch, which can be useful for managing
memory usage when adding a large number of documents.Optional list of metadata dicts associated with the texts.
Optional list of keys to associate with the documents.
Additional keyword arguments.
Common kwargs include:
ids: Optional list of ids to associate with the documents.refresh_indices: Whether to refresh the Redis indices
after adding the texts.
True.create_index_if_not_exists: Whether to create the Redis
index if it doesn't already exist.
True.batch_size: Optional. Number of texts to add to the
index at a time.
1000.