-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embeddings index checkpointing, closes #695
- Loading branch information
1 parent
8a3ed27
commit a1a7d34
Showing
8 changed files
with
168 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Recovery module | ||
""" | ||
|
||
import os | ||
import shutil | ||
|
||
import numpy as np | ||
|
||
|
||
class Recovery: | ||
""" | ||
Vector embeddings recovery. This class handles streaming embeddings from a vector checkpoint file. | ||
""" | ||
|
||
def __init__(self, checkpoint, vectorsid): | ||
""" | ||
Creates a Recovery instance. | ||
Args: | ||
checkpoint: checkpoint directory | ||
vectorsid: vectors uid for current configuration | ||
""" | ||
|
||
self.spool, self.path = None, None | ||
|
||
# Get unique file id | ||
path = f"{checkpoint}/{vectorsid}" | ||
if os.path.exists(path): | ||
# Generate recovery path | ||
self.path = f"{checkpoint}/recovery" | ||
|
||
# Copy current checkpoint to recovery | ||
shutil.copyfile(path, self.path) | ||
|
||
# Open file an return | ||
# pylint: disable=R1732 | ||
self.spool = open(self.path, "rb") | ||
|
||
def __call__(self): | ||
""" | ||
Reads and returns the next batch of embeddings. | ||
Returns | ||
batch of embeddings | ||
""" | ||
|
||
try: | ||
return np.load(self.spool) if self.spool else None | ||
except EOFError: | ||
# End of spool file, cleanup | ||
self.spool.close() | ||
os.remove(self.path) | ||
|
||
# Clear parameters | ||
self.spool, self.path = None, None | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters