Harrison/weaviate improvements (#433)

Co-authored-by: Connor Shorten <connorshorten300@gmail.com>
This commit is contained in:
Harrison Chase 2022-12-27 08:23:13 -05:00 committed by GitHub
parent b7566b5ec3
commit 150b67de10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
from typing import Any, Iterable, List, Optional from typing import Any, Iterable, List, Optional
from uuid import uuid4
from langchain.docstore.document import Document from langchain.docstore.document import Document
from langchain.embeddings.base import Embeddings from langchain.embeddings.base import Embeddings
@ -52,8 +53,23 @@ class Weaviate(VectorStore):
def add_texts( def add_texts(
self, texts: Iterable[str], metadatas: Optional[List[dict]] = None self, texts: Iterable[str], metadatas: Optional[List[dict]] = None
) -> List[str]: ) -> List[str]:
"""Not implemented for Weaviate yet.""" """Upload texts with metadata (properties) to Weaviate."""
raise NotImplementedError("weaviate does not currently support `add_texts`.") from weaviate.util import get_valid_uuid
with self._client.batch as batch:
ids = []
for i, doc in enumerate(texts):
data_properties = {
self._text_key: doc,
}
if metadatas is not None:
for key in metadatas[i].keys():
data_properties[key] = metadatas[i][key]
_id = get_valid_uuid(uuid4())
batch.add_data_object(data_properties, self._index_name, _id)
ids.append(_id)
return ids
def similarity_search(self, query: str, k: int = 4) -> List[Document]: def similarity_search(self, query: str, k: int = 4) -> List[Document]:
"""Look up similar documents in weaviate.""" """Look up similar documents in weaviate."""