forked from Archives/langchain
Harrison/weaviate fixes (#2872)
Co-authored-by: cs0lar <cristiano.solarino@gmail.com> Co-authored-by: cs0lar <cristiano.solarino@brightminded.com>fix_agent_callbacks
parent
07d7096de6
commit
1e9378d0a8
@ -0,0 +1,22 @@
|
||||
version: '3.4'
|
||||
|
||||
services:
|
||||
weaviate:
|
||||
command:
|
||||
- --host
|
||||
- 0.0.0.0
|
||||
- --port
|
||||
- '8080'
|
||||
- --scheme
|
||||
- http
|
||||
image: semitechnologies/weaviate:1.18.2
|
||||
ports:
|
||||
- 8080:8080
|
||||
restart: on-failure:0
|
||||
environment:
|
||||
QUERY_DEFAULTS_LIMIT: 25
|
||||
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
|
||||
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
|
||||
DEFAULT_VECTORIZER_MODULE: 'none'
|
||||
ENABLE_MODULES: ''
|
||||
CLUSTER_HOSTNAME: 'node1'
|
@ -0,0 +1,51 @@
|
||||
"""Test Weaviate functionality."""
|
||||
import logging
|
||||
from typing import Generator, Union
|
||||
|
||||
import pytest
|
||||
from weaviate import Client
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.embeddings.openai import OpenAIEmbeddings
|
||||
from langchain.vectorstores.weaviate import Weaviate
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
"""
|
||||
cd tests/integration_tests/vectorstores/docker-compose
|
||||
docker compose -f weaviate.yml up
|
||||
"""
|
||||
|
||||
|
||||
class TestWeaviate:
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
def weaviate_url(self) -> Union[str, Generator[str, None, None]]:
|
||||
"""Return the weaviate url."""
|
||||
url = "http://localhost:8080"
|
||||
yield url
|
||||
|
||||
# Clear the test index
|
||||
client = Client(url)
|
||||
client.schema.delete_all()
|
||||
|
||||
def test_similarity_search_without_metadata(self, weaviate_url: str) -> None:
|
||||
"""Test end to end construction and search without metadata."""
|
||||
texts = ["foo", "bar", "baz"]
|
||||
docsearch = Weaviate.from_texts(
|
||||
texts,
|
||||
OpenAIEmbeddings(),
|
||||
weaviate_url=weaviate_url,
|
||||
)
|
||||
|
||||
output = docsearch.similarity_search("foo", k=1)
|
||||
assert output == [Document(page_content="foo")]
|
||||
|
||||
def test_similarity_search_with_metadata(self, weaviate_url: str) -> None:
|
||||
"""Test end to end construction and search with metadata."""
|
||||
texts = ["foo", "bar", "baz"]
|
||||
metadatas = [{"page": i} for i in range(len(texts))]
|
||||
docsearch = Weaviate.from_texts(
|
||||
texts, OpenAIEmbeddings(), metadatas=metadatas, weaviate_url=weaviate_url
|
||||
)
|
||||
output = docsearch.similarity_search("foo", k=1)
|
||||
assert output == [Document(page_content="foo", metadata={"page": 0})]
|
Loading…
Reference in New Issue