-
Notifications
You must be signed in to change notification settings - Fork 8
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
More MessageDB improvements, including timestamp constraints in getting chatlog (messages since timestamp) #67
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4eb7975
Implement pgvector_message.get_chatlog(), with support for date const…
uogbuji 33c1ba2
Lint fixes
uogbuji 0b1117c
Nip the tempting inconsisency in the bud. Rename get_chatlog to get_m…
uogbuji 039013a
Returning messages since a date was mistakenly returning oldest rathe…
uogbuji a341326
Add a test for limit returning most recent messages
uogbuji 58549b4
Update CHANGELOG.md
uogbuji 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
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,5 +1,19 @@ | ||
# SPDX-FileCopyrightText: 2023-present Oori Data <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# test/embedding/conftest.py | ||
''' | ||
Fixtures/setup/teardown for embedding tests | ||
''' | ||
|
||
import sys | ||
import os | ||
import pytest | ||
import pytest_asyncio | ||
from unittest.mock import MagicMock, DEFAULT # noqa: F401 | ||
|
||
import numpy as np | ||
from ogbujipt.embedding.pgvector import MessageDB, DataDB, DocDB | ||
|
||
|
||
@pytest.fixture | ||
def CORRECT_STRING(): | ||
|
@@ -67,3 +81,57 @@ def HITHERE_all_MiniLM_L12_v2(): | |
-0.071223356, 0.0019683593, 0.032683503, -0.08899012, 0.10160039, 0.04948275, 0.048017487, -0.046223965, | ||
0.032460734, -0.043729845, 0.030224336, -0.019220904, 0.08223829, 0.03851222, -0.016376046, 0.041965306, | ||
0.0445879, -0.03780432, -0.024826797, 0.014669102, 0.057102628, -0.031820614, 0.0027352672, 0.052658144]) | ||
|
||
# XXX: This stanza to go away once mocking is complete - Kai | ||
HOST = os.environ.get('PG_HOST', 'localhost') | ||
DB_NAME = os.environ.get('PG_DATABASE', 'mock_db') | ||
USER = os.environ.get('PG_USER', 'mock_user') | ||
PASSWORD = os.environ.get('PG_PASSWORD', 'mock_password') | ||
PORT = os.environ.get('PG_PORT', 5432) | ||
|
||
|
||
# XXX: Move to a fixture? | ||
# Definitely don't want to even import SentenceTransformer class due to massive side-effects | ||
class SentenceTransformer(object): | ||
def __init__(self, model_name_or_path): | ||
self.encode = MagicMock() | ||
|
||
|
||
DB_CLASS = { | ||
'test/embedding/test_pgvector_message.py': MessageDB, | ||
'test/embedding/test_pgvector_data.py': DataDB, | ||
'test/embedding/test_pgvector_doc.py': DocDB, | ||
} | ||
|
||
|
||
@pytest_asyncio.fixture # Notice the async aware fixture declaration | ||
async def DB(request): | ||
testname = request.node.name | ||
testfile = request.node.location[0] | ||
table_name = testname.lower() | ||
print(f'DB setup for test: {testname}. Table name {table_name}', file=sys.stderr) | ||
dummy_model = SentenceTransformer('mock_transformer') | ||
dummy_model.encode.return_value = np.array([1, 2, 3]) | ||
try: | ||
vDB = await DB_CLASS[testfile].from_conn_params( | ||
embedding_model=dummy_model, | ||
table_name=table_name, | ||
db_name=DB_NAME, | ||
host=HOST, | ||
port=int(PORT), | ||
user=USER, | ||
password=PASSWORD) | ||
except ConnectionRefusedError: | ||
pytest.skip("No Postgres instance made available for test. Skipping.", allow_module_level=True) | ||
if vDB is None: | ||
pytest.skip("No Postgres instance made available for test. Skipping.", allow_module_level=True) | ||
|
||
# Create table | ||
await vDB.drop_table() | ||
assert not await vDB.table_exists(), Exception("Table exists before creation") | ||
await vDB.create_table() | ||
assert await vDB.table_exists(), Exception("Table does not exist after creation") | ||
# The test will take control upon the yield | ||
yield vDB | ||
# Teardown: Drop table | ||
await vDB.drop_table() |
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.
huh, the
since
arg is cool