Add text documents to the vector store.
Example:
from langchain_redis import RedisVectorStore
from langchain_openai import OpenAIEmbeddings
vector_store = RedisVectorStore(
embeddings=OpenAIEmbeddings(),
index_name="langchain-demo",
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 controls Redis pipeline writes performed by RedisVL.
Texts, embeddings, and records are still prepared in memory before
the load operation.Optional list of metadata dicts associated with the texts.
Optional list of keys to associate with the documents.
Optional number of records to write in each Redis pipeline execution. If omitted, RedisVL's default is used.
Additional keyword arguments.
Common kwargs include:
ids: Optional list of ids to associate with the documents.