mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
The #1088 introduced a bug in Qdrant integration. That PR reverts those changes and provides class attributes to ensure consistent payload keys. In addition to that, an exception will be thrown if any of texts is None (that could have been an issue reported in #1087)
This commit is contained in:
parent
6322b6f657
commit
ab1a3cccac
@ -25,6 +25,9 @@ class Qdrant(VectorStore):
|
||||
qdrant = Qdrant(client, collection_name, embedding_function)
|
||||
"""
|
||||
|
||||
CONTENT_KEY = "page_content"
|
||||
METADATA_KEY = "metadata"
|
||||
|
||||
def __init__(self, client: Any, collection_name: str, embedding_function: Callable):
|
||||
"""Initialize with necessary components."""
|
||||
try:
|
||||
@ -213,17 +216,25 @@ class Qdrant(VectorStore):
|
||||
def _build_payloads(
|
||||
cls, texts: Iterable[str], metadatas: Optional[List[dict]]
|
||||
) -> List[dict]:
|
||||
return [
|
||||
{
|
||||
"page_content": text,
|
||||
"metadata": metadatas[i] if metadatas is not None else None,
|
||||
}
|
||||
for i, text in enumerate(texts)
|
||||
]
|
||||
payloads = []
|
||||
for i, text in enumerate(texts):
|
||||
if text is None:
|
||||
raise ValueError(
|
||||
"At least one of the texts is None. Please remove it before "
|
||||
"calling .from_texts or .add_texts on Qdrant instance."
|
||||
)
|
||||
payloads.append(
|
||||
{
|
||||
cls.CONTENT_KEY: text,
|
||||
cls.METADATA_KEY: metadatas[i] if metadatas is not None else None,
|
||||
}
|
||||
)
|
||||
|
||||
return payloads
|
||||
|
||||
@classmethod
|
||||
def _document_from_scored_point(cls, scored_point: Any) -> Document:
|
||||
return Document(
|
||||
page_content=scored_point.payload.get("content"),
|
||||
metadata=scored_point.payload.get("metadata") or {},
|
||||
page_content=scored_point.payload.get(cls.CONTENT_KEY),
|
||||
metadata=scored_point.payload.get(cls.METADATA_KEY) or {},
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user