Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ testpaths = [
]
filterwarnings = [
"error",
# This is coming from the nested dependency
# chromadb -> opentelemetry-exporter-otlp-proto-grpc -> googleapis-common-protos
# This will be resolved by https://github.com/googleapis/python-api-common-protos/pull/187
"ignore::DeprecationWarning:pkg_resources",
"ignore::DeprecationWarning:google.rpc",
]
xfail_strict = true

Expand Down
Empty file.
43 changes: 43 additions & 0 deletions tests/source_storages/test_source_storages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import uuid

import pytest

from ragna import Config
from ragna.core import LocalDocument
from ragna.source_storages import Chroma, LanceDB


@pytest.mark.parametrize("source_storage_cls", [Chroma, LanceDB])
def test_smoke(tmp_path, source_storage_cls):
document_root = tmp_path / "documents"
document_root.mkdir()
documents = []
for idx in range(10):
path = document_root / f"irrelevant{idx}.txt"
with open(path, "w") as file:
file.write(f"This is irrelevant information for the {idx}. time!\n")

documents.append(LocalDocument(path))

secret = "Ragna"
path = document_root / "secret.txt"
with open(path, "w") as file:
file.write(f"The secret is {secret}!\n")

documents.insert(len(documents) // 2, LocalDocument(path))

config = Config(local_cache_root=tmp_path)
source_storage = source_storage_cls(config)

# Hardcoding a chat_id here only works because all tested source storages only
# require this.
# TODO: make this more flexible by taking required parameters as part of the
# parametrization.
chat_id = uuid.uuid4()

source_storage.store(documents, chat_id=chat_id)

prompt = "What is the secret?"
sources = source_storage.retrieve(documents, prompt, chat_id=chat_id)

assert secret in sources[0].content