Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add batch_size to qdrant __init__ #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/qdrant_haystack/document_stores/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(
init_from: Optional[dict] = None,
wait_result_from_api: bool = True,
metadata: Optional[dict] = None,
batch_size: int = 10_000,
):
super().__init__()

Expand Down Expand Up @@ -108,6 +109,7 @@ def __init__(
# Make sure the collection is properly set up
self._set_up_collection(index, embedding_dim, recreate_index, similarity)

self.batch_size = batch_size
self.embedding_dim = embedding_dim
self.content_field = content_field
self.name_field = name_field
Expand All @@ -130,9 +132,10 @@ def get_all_documents(
index: Optional[str] = None,
filters: Optional[FilterType] = None,
return_embedding: Optional[bool] = None,
batch_size: int = 10_000,
batch_size: Optional[int] = None,
headers: Optional[Dict[str, str]] = None,
) -> List[Document]:
batch_size = batch_size or self.batch_size
return list(
self.get_all_documents_generator(
index, filters, return_embedding, batch_size, headers
Expand All @@ -144,9 +147,10 @@ def get_all_documents_generator(
index: Optional[str] = None,
filters: Optional[FilterType] = None,
return_embedding: Optional[bool] = None,
batch_size: int = 10_000,
batch_size: Optional[int] = None,
headers: Optional[Dict[str, str]] = None,
) -> Generator[Document, None, None]:
batch_size = batch_size or self.batch_size
index = index or self.index
qdrant_filters = self.qdrant_filter_converter.convert(filters)

Expand Down Expand Up @@ -185,11 +189,11 @@ def get_documents_by_id(
self,
ids: List[str],
index: Optional[str] = None,
batch_size: int = 10_000,
batch_size: Optional[int] = None,
headers: Optional[Dict[str, str]] = None,
) -> List[Document]:
index = index or self.index

batch_size = batch_size or self.batch_size
documents: List[Document] = []

next_offset = None
Expand Down Expand Up @@ -279,11 +283,12 @@ def write_documents(
self,
documents: Union[List[dict], List[Document]],
index: Optional[str] = None,
batch_size: int = 10_000,
batch_size: Optional[int] = None,
duplicate_documents: Optional[str] = None,
headers: Optional[Dict[str, str]] = None,
):
index = index or self.index
batch_size = batch_size or self.batch_size
self._set_up_collection(index, self.embedding_dim, False, self.similarity)
field_map = self._create_document_field_map()

Expand Down