-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rag): parameterize chat similarity token limits (#141)
Parameterize similarity chat token limits. The result of this is to increase the context size and thus improve accuracy of results.
- Loading branch information
Showing
5 changed files
with
80 additions
and
1 deletion.
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
Empty file.
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,62 @@ | ||
import pathlib | ||
|
||
import pytest | ||
from injector import Injector | ||
from llama_index.core.base.llms.types import ChatMessage | ||
|
||
from nesis.rag.core.server.chat.chat_service import ChatService, Completion | ||
from nesis.rag.core.server.ingest.ingest_service import IngestService | ||
from nesis.rag.core.settings.settings import Settings | ||
from nesis.rag import tests | ||
from nesis.rag.core.server.ingest.model import IngestedDoc | ||
|
||
|
||
@pytest.fixture | ||
def injector(settings) -> Injector: | ||
from nesis.rag.core.di import create_application_injector | ||
|
||
return create_application_injector(settings=settings) | ||
|
||
|
||
@pytest.fixture | ||
def settings() -> Settings: | ||
from nesis.rag.core.settings.settings import settings | ||
|
||
return settings( | ||
overrides={ | ||
"llm": {"mode": "mock", "token_limit": 100000}, | ||
"vectorstore": {"similarity_top_k": "20"}, | ||
} | ||
) | ||
|
||
|
||
def test_chat_service_similarity_top_k(injector): | ||
""" | ||
Test to ensure similarity_top_k setting takes effect. | ||
""" | ||
file_path: pathlib.Path = ( | ||
pathlib.Path(tests.__file__).parent.absolute() / "resources" / "rfc791.txt" | ||
) | ||
|
||
ingest_service = injector.get(IngestService) | ||
|
||
ingested_list: list[IngestedDoc] = ingest_service.ingest_file( | ||
file_name=file_path.name, | ||
file_data=file_path, | ||
metadata={ | ||
"file_name": str(file_path.absolute()), | ||
"datasource": "rfc-documents", | ||
}, | ||
) | ||
|
||
chat_service = injector.get(ChatService) | ||
completion: Completion = chat_service.chat( | ||
use_context=True, | ||
messages=[ | ||
ChatMessage.from_str( | ||
content="describe the internet protocol from the darpa internet program" | ||
) | ||
], | ||
) | ||
|
||
assert len(completion.sources) == 20 |