MCPcopy Create free account
hub / github.com/MinishLab/vicinity / load

Method load

vicinity/vicinity.py:205–234  ·  view source on GitHub ↗

Load a Vicinity instance in fast format. As described above, the fast format stores the words and vectors of the Vicinity instance separately and is drastically faster than loading from .txt files. :param filename: The filename to load. :return: A V

(cls, filename: PathLike)

Source from the content-addressed store, hash-verified

203
204 @classmethod
205 def load(cls, filename: PathLike) -> Vicinity[Any]:
206 """
207 Load a Vicinity instance in fast format.
208
209 As described above, the fast format stores the words and vectors of the
210 Vicinity instance separately and is drastically faster than loading from
211 .txt files.
212
213 :param filename: The filename to load.
214 :return: A Vicinity instance.
215 """
216 folder_path = Path(filename)
217
218 with open(folder_path / "data.json", "rb") as file_handle:
219 data: dict[str, Any] = orjson.loads(file_handle.read())
220 items: Sequence[Any] = data["items"]
221
222 metadata: dict[str, Any] = data["metadata"]
223 backend_type = Backend(data["backend_type"])
224
225 backend_cls: type[AbstractBackend] = get_backend_class(backend_type)
226 backend = backend_cls.load(folder_path)
227 if Path(folder_path / "store").exists():
228 vector_store = BasicVectorStore.load(folder_path / "store")
229 else:
230 vector_store = None
231
232 instance = cls(items, backend, metadata=metadata, vector_store=vector_store)
233
234 return instance
235
236 def insert(self, tokens: Sequence[T], vectors: npt.NDArray) -> None:
237 """

Calls 2

BackendClass · 0.90
get_backend_classFunction · 0.90