-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: Added test case for discourse query engine preparation!
- Loading branch information
1 parent
8cfc55f
commit 97902de
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
import unittest | ||
|
||
from llama_index.core.base_query_engine import BaseQueryEngine | ||
from llama_index.vector_stores import ExactMatchFilter, FilterCondition, MetadataFilters | ||
from utils.query_engine.discourse_query_engine import prepare_discourse_engine | ||
|
||
|
||
class TestPrepareDiscordEngine(unittest.TestCase): | ||
def setUp(self): | ||
# Set up environment variables for testing | ||
os.environ["CHUNK_SIZE"] = "128" | ||
os.environ["EMBEDDING_DIM"] = "256" | ||
os.environ["K1_RETRIEVER_SEARCH"] = "20" | ||
os.environ["K2_RETRIEVER_SEARCH"] = "5" | ||
os.environ["D_RETRIEVER_SEARCH"] = "3" | ||
|
||
def test_prepare_discord_engine(self): | ||
community_id = "123456" | ||
topic_names = ["topic1", "topic2"] | ||
category_names = ["category1", "category2"] | ||
days = ["2022-01-01", "2022-01-02"] | ||
|
||
# Call the function | ||
query_engine = prepare_discourse_engine( | ||
community_id=community_id, | ||
category_names=category_names, | ||
topic_names=topic_names, | ||
days=days, | ||
testing=True, | ||
) | ||
|
||
# Assertions | ||
self.assertIsInstance(query_engine, BaseQueryEngine) | ||
|
||
expected_filter = MetadataFilters( | ||
filters=[ | ||
ExactMatchFilter(key="category", value="category1"), | ||
ExactMatchFilter(key="category", value="category2"), | ||
ExactMatchFilter(key="topic", value="topic1"), | ||
ExactMatchFilter(key="topic", value="topic2"), | ||
ExactMatchFilter(key="date", value="2022-01-01"), | ||
ExactMatchFilter(key="date", value="2022-01-02"), | ||
], | ||
condition=FilterCondition.OR, | ||
) | ||
|
||
self.assertEqual(query_engine.retriever._filters, expected_filter) | ||
# this is the secondary search, so K2 should be for this | ||
self.assertEqual(query_engine.retriever._similarity_top_k, 5) |