@ -2,7 +2,7 @@
from __future__ import annotations
from __future__ import annotations
from abc import ABC , abstractmethod
from abc import ABC , abstractmethod
from typing import Any , Dict , Iterable , List , Optional
from typing import Any , Dict , Iterable , List , Optional , Type , TypeVar
from pydantic import BaseModel , Field , root_validator
from pydantic import BaseModel , Field , root_validator
@ -10,6 +10,8 @@ from langchain.docstore.document import Document
from langchain . embeddings . base import Embeddings
from langchain . embeddings . base import Embeddings
from langchain . schema import BaseRetriever
from langchain . schema import BaseRetriever
VST = TypeVar ( " VST " , bound = " VectorStore " )
class VectorStore ( ABC ) :
class VectorStore ( ABC ) :
""" Interface for vector stores. """
""" Interface for vector stores. """
@ -153,11 +155,11 @@ class VectorStore(ABC):
@classmethod
@classmethod
def from_documents (
def from_documents (
cls ,
cls : Type [ VST ] ,
documents : List [ Document ] ,
documents : List [ Document ] ,
embedding : Embeddings ,
embedding : Embeddings ,
* * kwargs : Any ,
* * kwargs : Any ,
) - > V ectorStore :
) - > V ST :
""" Return VectorStore initialized from documents and embeddings. """
""" Return VectorStore initialized from documents and embeddings. """
texts = [ d . page_content for d in documents ]
texts = [ d . page_content for d in documents ]
metadatas = [ d . metadata for d in documents ]
metadatas = [ d . metadata for d in documents ]
@ -165,11 +167,11 @@ class VectorStore(ABC):
@classmethod
@classmethod
async def afrom_documents (
async def afrom_documents (
cls ,
cls : Type [ VST ] ,
documents : List [ Document ] ,
documents : List [ Document ] ,
embedding : Embeddings ,
embedding : Embeddings ,
* * kwargs : Any ,
* * kwargs : Any ,
) - > V ectorStore :
) - > V ST :
""" Return VectorStore initialized from documents and embeddings. """
""" Return VectorStore initialized from documents and embeddings. """
texts = [ d . page_content for d in documents ]
texts = [ d . page_content for d in documents ]
metadatas = [ d . metadata for d in documents ]
metadatas = [ d . metadata for d in documents ]
@ -178,22 +180,22 @@ class VectorStore(ABC):
@classmethod
@classmethod
@abstractmethod
@abstractmethod
def from_texts (
def from_texts (
cls ,
cls : Type [ VST ] ,
texts : List [ str ] ,
texts : List [ str ] ,
embedding : Embeddings ,
embedding : Embeddings ,
metadatas : Optional [ List [ dict ] ] = None ,
metadatas : Optional [ List [ dict ] ] = None ,
* * kwargs : Any ,
* * kwargs : Any ,
) - > V ectorStore :
) - > V ST :
""" Return VectorStore initialized from texts and embeddings. """
""" Return VectorStore initialized from texts and embeddings. """
@classmethod
@classmethod
async def afrom_texts (
async def afrom_texts (
cls ,
cls : Type [ VST ] ,
texts : List [ str ] ,
texts : List [ str ] ,
embedding : Embeddings ,
embedding : Embeddings ,
metadatas : Optional [ List [ dict ] ] = None ,
metadatas : Optional [ List [ dict ] ] = None ,
* * kwargs : Any ,
* * kwargs : Any ,
) - > V ectorStore :
) - > V ST :
""" Return VectorStore initialized from texts and embeddings. """
""" Return VectorStore initialized from texts and embeddings. """
raise NotImplementedError
raise NotImplementedError