Create VectorStore interface (#92)

This commit is contained in:
Samantha Whitmore 2022-11-08 18:19:39 -08:00 committed by GitHub
parent b9f61390e9
commit 61f12229df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 9 deletions

View File

@ -8,9 +8,9 @@
"outputs": [],
"source": [
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from langchain.elastic_vector_search import ElasticVectorSearch\n",
"from langchain.faiss import FAISS\n",
"from langchain.text_splitter import CharacterTextSplitter"
"from langchain.text_splitter import CharacterTextSplitter\n",
"from langchain.vectorstores.elastic_vector_search import ElasticVectorSearch\n",
"from langchain.vectorstores.faiss import FAISS"
]
},
{
@ -69,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"id": "4906b8a3",
"metadata": {},
"outputs": [],
@ -82,7 +82,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"id": "95f9eee9",
"metadata": {},
"outputs": [

View File

@ -16,11 +16,10 @@ from langchain.chains import (
SQLDatabaseChain,
)
from langchain.docstore import Wikipedia
from langchain.elastic_vector_search import ElasticVectorSearch
from langchain.faiss import FAISS
from langchain.llms import Cohere, HuggingFaceHub, OpenAI
from langchain.prompts import BasePrompt, DynamicPrompt, Prompt
from langchain.sql_database import SQLDatabase
from langchain.vectorstores import FAISS, ElasticVectorSearch
__all__ = [
"LLMChain",

View File

@ -0,0 +1,6 @@
"""Wrappers on top of vector stores."""
from langchain.vectorstores.base import VectorStore
from langchain.vectorstores.elastic_vector_search import ElasticVectorSearch
from langchain.vectorstores.faiss import FAISS
__all__ = ["ElasticVectorSearch", "FAISS", "VectorStore"]

View File

@ -0,0 +1,13 @@
"""Interface for vector stores."""
from abc import ABC, abstractmethod
from typing import List
from langchain.docstore.document import Document
class VectorStore(ABC):
"""Interface for vector stores."""
@abstractmethod
def similarity_search(self, query: str, k: int = 4) -> List[Document]:
"""Return docs most similar to query."""

View File

@ -4,6 +4,7 @@ from typing import Callable, Dict, List
from langchain.docstore.document import Document
from langchain.embeddings.base import Embeddings
from langchain.vectorstores.base import VectorStore
def _default_text_mapping(dim: int) -> Dict:
@ -27,7 +28,7 @@ def _default_script_query(query_vector: List[int]) -> Dict:
}
class ElasticVectorSearch:
class ElasticVectorSearch(VectorStore):
"""Wrapper around Elasticsearch as a vector database.
Example:

View File

@ -7,9 +7,10 @@ from langchain.docstore.base import Docstore
from langchain.docstore.document import Document
from langchain.docstore.in_memory import InMemoryDocstore
from langchain.embeddings.base import Embeddings
from langchain.vectorstores.base import VectorStore
class FAISS:
class FAISS(VectorStore):
"""Wrapper around FAISS vector database.
To use, you should have the ``faiss`` python package installed.