kssrag 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tests/test_basic.py ADDED
@@ -0,0 +1,43 @@
1
+ import pytest
2
+ import os
3
+ import tempfile
4
+ from kssrag import KSSRAG, Config
5
+
6
+ def test_text_rag():
7
+ """Test basic text RAG functionality"""
8
+ # Create a temporary text file
9
+ with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
10
+ f.write("This is a test document about artificial intelligence and machine learning.")
11
+ temp_file = f.name
12
+
13
+ try:
14
+ # Initialize with test config
15
+ config = Config(
16
+ OPENROUTER_API_KEY=os.getenv("OPENROUTER_API_KEY", "test_key"),
17
+ MAX_DOCS_FOR_TESTING=1
18
+ )
19
+
20
+ rag = KSSRAG(config=config)
21
+ rag.load_document(temp_file, format="text")
22
+
23
+ # Test query
24
+ response = rag.query("What is this document about?")
25
+
26
+ assert isinstance(response, str)
27
+ assert len(response) > 0
28
+
29
+ finally:
30
+ # Clean up
31
+ os.unlink(temp_file)
32
+
33
+ def test_config_validation():
34
+ """Test configuration validation"""
35
+ config = Config(
36
+ OPENROUTER_API_KEY="test_key",
37
+ CHUNK_SIZE=500,
38
+ CHUNK_OVERLAP=50
39
+ )
40
+
41
+ assert config.OPENROUTER_API_KEY == "test_key"
42
+ assert config.CHUNK_SIZE == 500
43
+ assert config.CHUNK_OVERLAP == 50
@@ -0,0 +1,35 @@
1
+ import pytest
2
+ import numpy as np
3
+ from kssrag.core.vectorstores import BM25VectorStore, TFIDFVectorStore
4
+
5
+ def test_bm25_vector_store():
6
+ """Test BM25 vector store functionality"""
7
+ documents = [
8
+ {"content": "This is a test document about Python programming.", "metadata": {"source": "test1"}},
9
+ {"content": "Another document about machine learning and AI.", "metadata": {"source": "test2"}},
10
+ {"content": "A third document on web development with JavaScript.", "metadata": {"source": "test3"}},
11
+ ]
12
+
13
+ vector_store = BM25VectorStore()
14
+ vector_store.add_documents(documents)
15
+
16
+ results = vector_store.retrieve("Python programming", top_k=2)
17
+
18
+ assert len(results) == 2
19
+ assert "Python" in results[0]["content"]
20
+
21
+ def test_tfidf_vector_store():
22
+ """Test TFIDF vector store functionality"""
23
+ documents = [
24
+ {"content": "This is a test document about Python programming.", "metadata": {"source": "test1"}},
25
+ {"content": "Another document about machine learning and AI.", "metadata": {"source": "test2"}},
26
+ {"content": "A third document on web development with JavaScript.", "metadata": {"source": "test3"}},
27
+ ]
28
+
29
+ vector_store = TFIDFVectorStore()
30
+ vector_store.add_documents(documents)
31
+
32
+ results = vector_store.retrieve("machine learning", top_k=2)
33
+
34
+ assert len(results) == 2
35
+ assert "machine learning" in results[0]["content"].lower()