Skip to content

Commit

Permalink
refactor: rename InMemory to InMemoryExactSearch
Browse files Browse the repository at this point in the history
Signed-off-by: anna-charlotte <charlotte.gerhaher@jina.ai>
  • Loading branch information
anna-charlotte committed Apr 27, 2023
1 parent 30456bc commit 5d2324a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions langchain/vectorstores/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from langchain.vectorstores.elastic_vector_search import ElasticVectorSearch
from langchain.vectorstores.faiss import FAISS
from langchain.vectorstores.hnsw_lib import HnswLib
from langchain.vectorstores.in_memory import InMemory
from langchain.vectorstores.in_memory_exact_search import InMemoryExactSearch
from langchain.vectorstores.milvus import Milvus
from langchain.vectorstores.myscale import MyScale, MyScaleSettings
from langchain.vectorstores.opensearch_vector_search import OpenSearchVectorSearch
Expand Down Expand Up @@ -37,5 +37,5 @@
"SupabaseVectorStore",
"AnalyticDB",
"HnswLib",
"InMemory",
"InMemoryExactSearch",
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
)


class InMemory(VecStoreFromDocIndex):
"""Wrapper around in-memory storage.
class InMemoryExactSearch(VecStoreFromDocIndex):
"""Wrapper around in-memory storage for exact search.
To use it, you should have the ``docarray`` package with version >=0.31.0 installed.
You can install it with `pip install "langchain[in_memory_store]"`.
Expand All @@ -23,7 +23,7 @@ def __init__(
embedding: Embeddings,
metric: str = "cosine_sim",
) -> None:
"""Initialize in-memory store.
"""Initialize InMemoryExactSearch store.
Args:
embedding (Embeddings): Embedding function.
Expand All @@ -45,8 +45,8 @@ def from_texts(
embedding: Embeddings,
metadatas: Optional[List[dict]] = None,
metric: str = "cosine_sim",
) -> InMemory:
"""Create an in-memory store and insert data.
) -> InMemoryExactSearch:
"""Create an InMemoryExactSearch store and insert data.
Args:
texts (List[str]): Text data.
Expand All @@ -58,7 +58,7 @@ def from_texts(
Defaults to "cosine_sim".
Returns:
InMemory Vector Store
InMemoryExactSearch Vector Store
"""
store = cls(
embedding=embedding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
import pytest

from langchain.schema import Document
from langchain.vectorstores.in_memory import InMemory
from langchain.vectorstores.in_memory_exact_search import InMemoryExactSearch
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings


def test_in_memory_vec_store_from_texts() -> None:
"""Test end to end construction and simple similarity search."""
texts = ["foo", "bar", "baz"]
docsearch = InMemory.from_texts(
docsearch = InMemoryExactSearch.from_texts(
texts,
FakeEmbeddings(),
)
assert isinstance(docsearch, InMemory)
assert isinstance(docsearch, InMemoryExactSearch)
assert docsearch.doc_index.num_docs() == 3


def test_in_memory_vec_store_add_texts(tmp_path) -> None:
"""Test end to end construction and simple similarity search."""
docsearch = InMemory(
docsearch = InMemoryExactSearch(
embedding=FakeEmbeddings(),
)
assert isinstance(docsearch, InMemory)
assert isinstance(docsearch, InMemoryExactSearch)
assert docsearch.doc_index.num_docs() == 0

texts = ["foo", "bar", "baz"]
Expand All @@ -34,7 +34,7 @@ def test_in_memory_vec_store_add_texts(tmp_path) -> None:
def test_sim_search(metric) -> None:
"""Test end to end construction and simple similarity search."""
texts = ["foo", "bar", "baz"]
in_memory_vec_store = InMemory.from_texts(
in_memory_vec_store = InMemoryExactSearch.from_texts(
texts=texts,
embedding=FakeEmbeddings(),
metric=metric,
Expand All @@ -48,7 +48,7 @@ def test_sim_search(metric) -> None:
def test_sim_search_with_score(metric) -> None:
"""Test end to end construction and similarity search with score."""
texts = ["foo", "bar", "baz"]
in_memory_vec_store = InMemory.from_texts(
in_memory_vec_store = InMemoryExactSearch.from_texts(
texts=texts,
embedding=FakeEmbeddings(),
metric=metric,
Expand All @@ -67,7 +67,7 @@ def test_sim_search_with_score(metric) -> None:
def test_sim_search_by_vector(metric) -> None:
"""Test end to end construction and similarity search by vector."""
texts = ["foo", "bar", "baz"]
in_memory_vec_store = InMemory.from_texts(
in_memory_vec_store = InMemoryExactSearch.from_texts(
texts=texts,
embedding=FakeEmbeddings(),
metric=metric,
Expand All @@ -84,7 +84,7 @@ def test_max_marginal_relevance_search(metric) -> None:
"""Test MRR search."""
texts = ["foo", "bar", "baz"]
metadatas = [{"page": i} for i in range(len(texts))]
docsearch = InMemory.from_texts(
docsearch = InMemoryExactSearch.from_texts(
texts,
FakeEmbeddings(),
metadatas=metadatas,
Expand Down

0 comments on commit 5d2324a

Please sign in to comment.