mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-07 20:15:40 +00:00
community[patch]: support momento vector index filter expressions (#14978)
**Description** For the Momento Vector Index (MVI) vector store implementation, pass through `filter_expression` kwarg to the MVI client, if specified. This change will enable the MVI self query implementation in a future PR. Also fixes some integration tests.
This commit is contained in:
parent
300c1cbf92
commit
1c934fff0e
@ -306,8 +306,13 @@ class MomentoVectorIndex(VectorStore):
|
|||||||
|
|
||||||
if "top_k" in kwargs:
|
if "top_k" in kwargs:
|
||||||
k = kwargs["k"]
|
k = kwargs["k"]
|
||||||
|
filter_expression = kwargs.get("filter_expression", None)
|
||||||
response = self._client.search(
|
response = self._client.search(
|
||||||
self.index_name, embedding, top_k=k, metadata_fields=ALL_METADATA
|
self.index_name,
|
||||||
|
embedding,
|
||||||
|
top_k=k,
|
||||||
|
metadata_fields=ALL_METADATA,
|
||||||
|
filter_expression=filter_expression,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not isinstance(response, Search.Success):
|
if not isinstance(response, Search.Success):
|
||||||
@ -366,8 +371,13 @@ class MomentoVectorIndex(VectorStore):
|
|||||||
from momento.requests.vector_index import ALL_METADATA
|
from momento.requests.vector_index import ALL_METADATA
|
||||||
from momento.responses.vector_index import SearchAndFetchVectors
|
from momento.responses.vector_index import SearchAndFetchVectors
|
||||||
|
|
||||||
|
filter_expression = kwargs.get("filter_expression", None)
|
||||||
response = self._client.search_and_fetch_vectors(
|
response = self._client.search_and_fetch_vectors(
|
||||||
self.index_name, embedding, top_k=fetch_k, metadata_fields=ALL_METADATA
|
self.index_name,
|
||||||
|
embedding,
|
||||||
|
top_k=fetch_k,
|
||||||
|
metadata_fields=ALL_METADATA,
|
||||||
|
filter_expression=filter_expression,
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(response, SearchAndFetchVectors.Success):
|
if isinstance(response, SearchAndFetchVectors.Success):
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Iterator, List
|
from typing import Generator, Iterator, List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
|
from langchain_community.document_loaders import TextLoader
|
||||||
from langchain_community.embeddings import OpenAIEmbeddings
|
from langchain_community.embeddings import OpenAIEmbeddings
|
||||||
from langchain_community.vectorstores import MomentoVectorIndex
|
from langchain_community.vectorstores import MomentoVectorIndex
|
||||||
|
|
||||||
@ -24,6 +26,23 @@ def wait() -> None:
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def embedding_openai() -> OpenAIEmbeddings:
|
||||||
|
if not os.environ.get("OPENAI_API_KEY"):
|
||||||
|
raise ValueError("OPENAI_API_KEY is not set")
|
||||||
|
return OpenAIEmbeddings()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
|
def texts() -> Generator[List[str], None, None]:
|
||||||
|
# Load the documents from a file located in the fixtures directory
|
||||||
|
documents = TextLoader(
|
||||||
|
os.path.join(os.path.dirname(__file__), "fixtures", "sharks.txt")
|
||||||
|
).load()
|
||||||
|
|
||||||
|
yield [doc.page_content for doc in documents]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def vector_store(
|
def vector_store(
|
||||||
embedding_openai: OpenAIEmbeddings, random_index_name: str
|
embedding_openai: OpenAIEmbeddings, random_index_name: str
|
||||||
|
Loading…
Reference in New Issue
Block a user