Add text documents to the vector store.
add_texts(
self,
texts: Iterable[str],
metadatas: Optional[List[Dict[str, Any]]] = None,
keys: Optional[List[str]] = None,
**kwargs: Any = {}
) -> List[str]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.| Name | Type | Description |
|---|---|---|
texts* | Iterable[str] | Iterable of strings to add to the vector store. |
metadatas | Optional[List[Dict[str, Any]]] | Default: NoneOptional list of metadata dicts associated with the texts. |
keys | Optional[List[str]] | Default: NoneOptional list of keys to associate with the documents. |
**kwargs | Any | Default: {}Additional keyword arguments. Common kwargs include:
|