forked from Archives/langchain
Create VectorStore interface (#92)
This commit is contained in:
parent
b9f61390e9
commit
61f12229df
@ -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": [
|
||||
|
@ -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",
|
||||
|
6
langchain/vectorstores/__init__.py
Normal file
6
langchain/vectorstores/__init__.py
Normal 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"]
|
13
langchain/vectorstores/base.py
Normal file
13
langchain/vectorstores/base.py
Normal 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."""
|
@ -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:
|
@ -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.
|
Loading…
Reference in New Issue
Block a user