Remove unnecessary method from Qdrant vectorstore and clean up docstrings (#2700)

**Problem:**

The `from_documents` method in Qdrant vectorstore is unnecessary because
it does not change any default behavior from the abstract base class
method of `from_documents` (contrast this with the method in Chroma
which makes a change from default and turns `embeddings` into an
Optional parameter).

Also, the docstrings need some cleanup.

**Solution:**

Remove unnecessary method and improve docstrings.

---------

Co-authored-by: Vijay Rajaram <vrajaram3@gatech.edu>
This commit is contained in:
vr140 2023-04-11 21:34:22 -07:00 committed by GitHub
parent 933dfac583
commit dd59193757
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ class Qdrant(VectorStore):
Example: Example:
.. code-block:: python .. code-block:: python
from qdrant_client import QdrantClient
from langchain import Qdrant from langchain import Qdrant
client = QdrantClient() client = QdrantClient()
@ -125,7 +126,7 @@ class Qdrant(VectorStore):
filter: Filter by metadata. Defaults to None. filter: Filter by metadata. Defaults to None.
Returns: Returns:
List of Documents most similar to the query and score for each List of Documents most similar to the query and score for each.
""" """
embedding = self.embedding_function(query) embedding = self.embedding_function(query)
results = self.client.search( results = self.client.search(
@ -157,6 +158,7 @@ class Qdrant(VectorStore):
query: Text to look up documents similar to. query: Text to look up documents similar to.
k: Number of Documents to return. Defaults to 4. k: Number of Documents to return. Defaults to 4.
fetch_k: Number of Documents to fetch to pass to MMR algorithm. fetch_k: Number of Documents to fetch to pass to MMR algorithm.
Defaults to 20.
Returns: Returns:
List of Documents selected by maximal marginal relevance. List of Documents selected by maximal marginal relevance.
@ -201,7 +203,7 @@ class Qdrant(VectorStore):
metadata_payload_key: str = METADATA_KEY, metadata_payload_key: str = METADATA_KEY,
**kwargs: Any, **kwargs: Any,
) -> Qdrant: ) -> Qdrant:
"""Construct Qdrant wrapper from raw documents. """Construct Qdrant wrapper from a list of texts.
Args: Args:
texts: A list of texts to be indexed in Qdrant. texts: A list of texts to be indexed in Qdrant.
@ -212,45 +214,50 @@ class Qdrant(VectorStore):
location: location:
If `:memory:` - use in-memory Qdrant instance. If `:memory:` - use in-memory Qdrant instance.
If `str` - use it as a `url` parameter. If `str` - use it as a `url` parameter.
If `None` - use default values for `host` and `port`. If `None` - fallback to relying on `host` and `port` parameters.
url: either host or str of "Optional[scheme], host, Optional[port], url: either host or str of "Optional[scheme], host, Optional[port],
Optional[prefix]". Default: `None` Optional[prefix]". Default: `None`
port: Port of the REST API interface. Default: 6333 port: Port of the REST API interface. Default: 6333
grpc_port: Port of the gRPC interface. Default: 6334 grpc_port: Port of the gRPC interface. Default: 6334
prefer_grpc: prefer_grpc:
If `true` - use gPRC interface whenever possible in custom methods. If true - use gPRC interface whenever possible in custom methods.
https: If `true` - use HTTPS(SSL) protocol. Default: `None` Default: False
api_key: API key for authentication in Qdrant Cloud. Default: `None` https: If true - use HTTPS(SSL) protocol. Default: None
api_key: API key for authentication in Qdrant Cloud. Default: None
prefix: prefix:
If not `None` - add `prefix` to the REST URL path. If not None - add prefix to the REST URL path.
Example: `service/v1` will result in Example: service/v1 will result in
`http://localhost:6333/service/v1/{qdrant-endpoint}` for REST API. http://localhost:6333/service/v1/{qdrant-endpoint} for REST API.
Default: `None` Default: None
timeout: timeout:
Timeout for REST and gRPC API requests. Timeout for REST and gRPC API requests.
Default: 5.0 seconds for REST and unlimited for gRPC Default: 5.0 seconds for REST and unlimited for gRPC
host: host:
Host name of Qdrant service. If url and host are None, set to Host name of Qdrant service. If url and host are None, set to
'localhost'. Default: `None` 'localhost'. Default: None
path: path:
Path in which the vectors will be stored while using local mode. Path in which the vectors will be stored while using local mode.
Default: `None` Default: None
collection_name: collection_name:
Name of the Qdrant collection to be used. If not provided, Name of the Qdrant collection to be used. If not provided,
will be created randomly. it will be created randomly. Default: None
distance_func: distance_func:
Distance function. One of the: "Cosine" / "Euclid" / "Dot". Distance function. One of: "Cosine" / "Euclid" / "Dot".
Default: "Cosine"
content_payload_key: content_payload_key:
A payload key used to store the content of the document. A payload key used to store the content of the document.
Default: "page_content"
metadata_payload_key: metadata_payload_key:
A payload key used to store the metadata of the document. A payload key used to store the metadata of the document.
Default: "metadata"
**kwargs: **kwargs:
Additional arguments passed directly into REST client initialization Additional arguments passed directly into REST client initialization
This is a user friendly interface that: This is a user friendly interface that:
1. Embeds documents. 1. Creates embeddings, one for each text
2. Creates an in memory docstore 2. Initializes the Qdrant database as an in-memory docstore by default
3. Initializes the Qdrant database (and overridable to a remote docstore)
3. Adds the text embeddings to the Qdrant database
This is intended to be a quick way to get started. This is intended to be a quick way to get started.