You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# These vectors can now be loaded with the LmdbEmbeddingsReader.
58
57
```
59
58
59
+
## LRU Cache
60
+
A reader with an LRU (Least Recently Used) cache is included. This will save the embeddings for the 50,000 most recently queried words and return the same object instead of querying the database each time. Its interface is the same as the standard reader.
61
+
See [functools.lru_cache](https://docs.python.org/3/library/functools.html#functools.lru_cache) in the standard library.
62
+
63
+
```python
64
+
from lmdb_embeddings.reader import LruCachedLmdbEmbeddingsReader
65
+
from lmdb_embeddings.exceptions import MissingWordError
By default, LMDB Embeddings uses pickle to serialize the vectors to bytes (optimized and pickled with the highest available protocol). However, it is very easy to use an alternative approach - simply inject the serializer and unserializer as callables into the `LmdbEmbeddingsWriter` and `LmdbEmbeddingsReader`.
62
78
@@ -68,7 +84,7 @@ from lmdb_embeddings.serializers import MsgpackSerializer
68
84
69
85
writer = LmdbEmbeddingsWriter(
70
86
iter_embeddings(),
71
-
serializer=MsgpackSerializer.serialize
87
+
serializer=MsgpackSerializer().serialize
72
88
).write(OUTPUT_DATABASE_FOLDER)
73
89
```
74
90
@@ -78,7 +94,7 @@ from lmdb_embeddings.serializers import MsgpackSerializer
0 commit comments