mirror of
https://github.com/hwchase17/langchain
synced 2024-11-04 06:00:26 +00:00
add serializer methods (#7914)
Description: I have added two methods serializer and deserializer methods. There was method called save local but it saves the to the local disk. I wanted the vectorstore in the format using which i can push it to the sql database's blob field. I have used this while i was working on something @rlancemartin, @eyurtsev --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
parent
b786335dd1
commit
47eea32f6a
@ -674,6 +674,23 @@ class FAISS(VectorStore):
|
|||||||
embeddings.embed_query, index, docstore, index_to_docstore_id, **kwargs
|
embeddings.embed_query, index, docstore, index_to_docstore_id, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def serialize_to_bytes(self) -> bytes:
|
||||||
|
"""Serialize FAISS index, docstore, and index_to_docstore_id to bytes."""
|
||||||
|
return pickle.dumps((self.index, self.docstore, self.index_to_docstore_id))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def deserialize_from_bytes(
|
||||||
|
cls,
|
||||||
|
serialized: bytes,
|
||||||
|
embeddings: Embeddings,
|
||||||
|
**kwargs: Any,
|
||||||
|
) -> FAISS:
|
||||||
|
"""Deserialize FAISS index, docstore, and index_to_docstore_id from bytes."""
|
||||||
|
index, docstore, index_to_docstore_id = pickle.loads(serialized)
|
||||||
|
return cls(
|
||||||
|
embeddings.embed_query, index, docstore, index_to_docstore_id, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
def _select_relevance_score_fn(self) -> Callable[[float], float]:
|
def _select_relevance_score_fn(self) -> Callable[[float], float]:
|
||||||
"""
|
"""
|
||||||
The 'correct' relevance function
|
The 'correct' relevance function
|
||||||
|
Loading…
Reference in New Issue
Block a user