-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added qdrant support for BaseEngine and added MediaWiki RAG! #60
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a8d7fb7
feat: Added qdrant support for BaseEngine!
amindadgar 66826b4
fix: isort issue!
amindadgar f32a46f
feat: Added missing service to docker-compose.test.yaml!
amindadgar f7d62fd
feat: Added MediaWiki query engine!
amindadgar 41093fb
fix: update mediaWiki name to match modules on mongodb!
amindadgar 9a9247d
fix: qdrant ip in docker-compose shouldn't be localhost!
amindadgar b1f15f4
fix: update retriever type assertion!
amindadgar 2533f36
fix: We still needed the PGVector engine for discord and discourse!
amindadgar 83aa683
fix: getting back the test case for pgvector engine!
amindadgar 04581b9
fix: qdrant properties!
amindadgar 62e3a22
fix: linter issues!
amindadgar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
6 changes: 3 additions & 3 deletions
6
tests/unit/test_base_engine.py → tests/unit/test_base_pg_engine.py
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
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,25 @@ | ||
from unittest import TestCase | ||
|
||
from utils.query_engine.base_qdrant_engine import BaseQdrantEngine | ||
|
||
|
||
class TestBaseQdrantEngine(TestCase): | ||
def test_setup_vector_store_index(self): | ||
""" | ||
Tests that _setup_vector_store_index creates a PGVectorAccess object | ||
and calls its load_index method. | ||
""" | ||
platform_table_name = "test_table" | ||
community_id = "123456" | ||
base_engine = BaseQdrantEngine( | ||
platform_name=platform_table_name, | ||
community_id=community_id, | ||
) | ||
base_engine = base_engine._setup_vector_store_index( | ||
testing=True, | ||
) | ||
|
||
expected_collection_name = f"{community_id}_{platform_table_name}" | ||
self.assertEqual( | ||
base_engine.vector_store.collection_name, expected_collection_name | ||
) |
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
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
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,17 @@ | ||
from unittest import TestCase | ||
|
||
from llama_index.core.indices.vector_store.retrievers.retriever import ( | ||
VectorIndexRetriever, | ||
) | ||
from utils.query_engine import MediaWikiQueryEngine | ||
|
||
|
||
class TestMediaWikiQueryEngine(TestCase): | ||
def setUp(self) -> None: | ||
community_id = "sample_community" | ||
self.notion_query_engine = MediaWikiQueryEngine(community_id) | ||
|
||
def test_prepare_engine(self): | ||
notion_query_engine = self.notion_query_engine.prepare(testing=True) | ||
print(notion_query_engine.__dict__) | ||
self.assertIsInstance(notion_query_engine.retriever, VectorIndexRetriever) |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# flake8: noqa | ||
from .gdrive import GDriveQueryEngine | ||
from .github import GitHubQueryEngine | ||
from .media_wiki import MediaWikiQueryEngine | ||
from .notion import NotionQueryEngine | ||
from .prepare_discord_query_engine import prepare_discord_engine_auto_filter | ||
from .subquery_gen_prompt import DEFAULT_GUIDANCE_SUB_QUESTION_PROMPT_TMPL |
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
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,67 @@ | ||
from bot.retrievers.utils.load_hyperparams import load_hyperparams | ||
from llama_index.core import VectorStoreIndex, get_response_synthesizer | ||
from llama_index.core.indices.vector_store.retrievers.retriever import ( | ||
VectorIndexRetriever, | ||
) | ||
from llama_index.core.query_engine import RetrieverQueryEngine | ||
from tc_hivemind_backend.qdrant_vector_access import QDrantVectorAccess | ||
|
||
|
||
class BaseQdrantEngine: | ||
def __init__(self, platform_name: str, community_id: str) -> None: | ||
""" | ||
initialize the qdrant db engine to query the database related to a community | ||
and the table related to the platform | ||
|
||
Parameters | ||
----------- | ||
platform_name : str | ||
the table representative of data for a specific platform | ||
community_id : str | ||
the database for a community | ||
normally the community database is saved as | ||
`community_{community_id}` | ||
""" | ||
self.platform_name = platform_name | ||
self.community_id = community_id | ||
self.collection_name = f"{self.community_id}_{platform_name}" | ||
|
||
def prepare(self, testing=False): | ||
vector_store_index = self._setup_vector_store_index( | ||
testing=testing, | ||
) | ||
_, similarity_top_k, _ = load_hyperparams() | ||
|
||
retriever = VectorIndexRetriever( | ||
index=vector_store_index, | ||
similarity_top_k=similarity_top_k, | ||
) | ||
query_engine = RetrieverQueryEngine( | ||
retriever=retriever, | ||
response_synthesizer=get_response_synthesizer(), | ||
) | ||
return query_engine | ||
|
||
def _setup_vector_store_index( | ||
self, | ||
testing: bool = False, | ||
**kwargs, | ||
) -> VectorStoreIndex: | ||
""" | ||
prepare the vector_store for querying data | ||
|
||
Parameters | ||
------------ | ||
testing : bool | ||
for testing purposes | ||
**kwargs : | ||
collection_name : str | ||
to override the default collection_name | ||
""" | ||
collection_name = kwargs.get("collection_name", self.collection_name) | ||
qdrant_vector = QDrantVectorAccess( | ||
collection_name=collection_name, | ||
testing=testing, | ||
) | ||
index = qdrant_vector.load_index() | ||
return index |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from utils.query_engine.base_engine import BaseEngine | ||
from utils.query_engine.base_qdrant_engine import BaseQdrantEngine | ||
|
||
|
||
class GDriveQueryEngine(BaseEngine): | ||
class GDriveQueryEngine(BaseQdrantEngine): | ||
def __init__(self, community_id: str) -> None: | ||
platform_name = "gdrive" | ||
super().__init__(platform_name, community_id) |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from utils.query_engine.base_engine import BaseEngine | ||
from utils.query_engine.base_qdrant_engine import BaseQdrantEngine | ||
|
||
|
||
class GitHubQueryEngine(BaseEngine): | ||
class GitHubQueryEngine(BaseQdrantEngine): | ||
def __init__(self, community_id: str) -> None: | ||
platform_name = "github" | ||
super().__init__(platform_name, community_id) |
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
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,7 @@ | ||
from utils.query_engine.base_qdrant_engine import BaseQdrantEngine | ||
|
||
|
||
class MediaWikiQueryEngine(BaseQdrantEngine): | ||
def __init__(self, community_id: str) -> None: | ||
platform_name = "mediawiki" | ||
super().__init__(platform_name, community_id) |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from utils.query_engine.base_engine import BaseEngine | ||
from utils.query_engine.base_qdrant_engine import BaseQdrantEngine | ||
|
||
|
||
class NotionQueryEngine(BaseEngine): | ||
class NotionQueryEngine(BaseQdrantEngine): | ||
def __init__(self, community_id: str) -> None: | ||
platform_name = "notion" | ||
super().__init__(platform_name, community_id) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the typo in the tool metadata name.
Committable suggestion