Skip to content

Commit

Permalink
fix: DocumentPath & CollectionPath are immutable (#768)
Browse files Browse the repository at this point in the history
* fix: `DocumentPath` & `CollectionPath` are immutable

* adjust changelog
  • Loading branch information
NickyHavoc authored Apr 22, 2024
1 parent 0421ab2 commit f52f1d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
- breaking change: `ExpandChunksOutput` now returns `ChunkWithStartEndIndices` instead of `TextChunk`
- breaking change: `MultipleChunkRetrieverQa`'s `AnswerSource` now contains `EnrichedChunk` instead of just the `TextChunk`


### New Features

### Fixes
- fix: `ChunkWithIndices` now additionally returns end_index
- fix: `DocumentPath` and `CollectionPath` are now immutable


## 0.9.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _to_modalities_json(self) -> Mapping[str, Any]:
}


class CollectionPath(BaseModel):
class CollectionPath(BaseModel, frozen=True):
"""Path to a collection.
Args:
Expand All @@ -64,7 +64,7 @@ class CollectionPath(BaseModel):
collection: str


class DocumentPath(BaseModel):
class DocumentPath(BaseModel, frozen=True):
"""Path to a document.
Args:
Expand Down
10 changes: 10 additions & 0 deletions tests/connectors/document_index/test_document_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,13 @@ def test_document_list_documents_with_matching_prefix(

assert len(filter_result) == 1
assert filter_result[0].document_path.document_name.startswith(prefix)


def test_document_path_is_immutable() -> None:
path = DocumentPath(
collection_path=CollectionPath(namespace="1", collection="2"), document_name="3"
)
dictionary = {}
dictionary[path] = 1

assert dictionary[path] == 1

0 comments on commit f52f1d6

Please sign in to comment.