Skip to content

Commit

Permalink
fix(QDrant): Resolve bug in document search functionality (langflow-a…
Browse files Browse the repository at this point in the history
…i#2518)

* Update Qdrant.py

fixed embeddings and distance_func for search_documents issue langflow-ai#2517

* [autofix.ci] apply automated fixes

* fixed documents link

* update params Qdrant

* Update Qdrant.py

* Update Qdrant.py

* Update Qdrant.py

* [autofix.ci] apply automated fixes

* Update args

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <[email protected]>
  • Loading branch information
3 people committed Jul 9, 2024
1 parent 3e8ee95 commit 1a10aa4
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/backend/base/langflow/components/vectorstores/Qdrant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import List

from langchain_community.vectorstores import Qdrant

from langflow.base.vectorstores.model import LCVectorStoreComponent
from langflow.helpers.data import docs_to_data
from langflow.io import (
Expand All @@ -13,15 +12,14 @@
DataInput,
MultilineInput,
)

from langflow.schema import Data
from langchain.embeddings.base import Embeddings # Certifique-se de que esta importação está correta


class QdrantVectorStoreComponent(LCVectorStoreComponent):
display_name = "Qdrant"
description = "Qdrant Vector Store with search capabilities"
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/qdrant"
name = "Qdrant"
icon = "Qdrant"

inputs = [
Expand Down Expand Up @@ -66,19 +64,18 @@ def _build_qdrant(self) -> Qdrant:
qdrant_kwargs = {
"collection_name": self.collection_name,
"content_payload_key": self.content_payload_key,
"distance_func": self.distance_func,
"metadata_payload_key": self.metadata_payload_key,
}

server_kwargs = {
"host": self.host,
"port": self.port,
"grpc_port": self.grpc_port,
"host": self.host if self.host else None,
"port": int(self.port), # Garantir que port seja um inteiro
"grpc_port": int(self.grpc_port), # Garantir que grpc_port seja um inteiro
"api_key": self.api_key,
"prefix": self.prefix,
"timeout": self.timeout,
"path": self.path,
"url": self.url,
"timeout": int(self.timeout) if self.timeout else None, # Garantir que timeout seja um inteiro
"path": self.path if self.path else None,
"url": self.url if self.url else None,
}

server_kwargs = {k: v for k, v in server_kwargs.items() if v is not None}
Expand All @@ -90,13 +87,17 @@ def _build_qdrant(self) -> Qdrant:
else:
documents.append(_input)

embedding = self.embedding
if not isinstance(embedding, Embeddings):
raise ValueError("Invalid embedding object")

if documents:
qdrant = Qdrant.from_documents(documents, embedding=self.embedding, **qdrant_kwargs)
qdrant = Qdrant.from_documents(documents, embeddings=embedding, **qdrant_kwargs)
else:
from qdrant_client import QdrantClient

client = QdrantClient(**server_kwargs)
qdrant = Qdrant(embedding_function=self.embedding.embed_query, client=client, **qdrant_kwargs)
qdrant = Qdrant(embeddings=embedding, client=client, **qdrant_kwargs)

return qdrant

Expand Down

0 comments on commit 1a10aa4

Please sign in to comment.