Enhancement: AI LLM chunk size and context window config (#12891)

This commit is contained in:
shamoon
2026-06-01 10:56:21 -07:00
committed by GitHub
parent bb860a5834
commit f6c865bf47
15 changed files with 318 additions and 36 deletions
+88 -1
View File
@@ -75,6 +75,8 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
"llm_embedding_backend": None,
"llm_embedding_model": None,
"llm_embedding_endpoint": None,
"llm_embedding_chunk_size": None,
"llm_context_size": None,
"llm_backend": None,
"llm_model": None,
"llm_api_key": None,
@@ -841,7 +843,7 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
with (
patch("documents.tasks.llmindex_index.apply_async") as mock_update,
patch("paperless_ai.indexing.vector_store_file_exists") as mock_exists,
patch("paperless.views.vector_store_file_exists") as mock_exists,
):
mock_exists.return_value = False
self.client.patch(
@@ -856,6 +858,91 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
)
mock_update.assert_called_once()
def test_update_llm_embedding_chunk_size_triggers_rebuild(self) -> None:
config = ApplicationConfiguration.objects.first()
assert config is not None
config.ai_enabled = True
config.llm_embedding_backend = "openai-like"
config.llm_embedding_chunk_size = 1024
config.save()
with (
patch("documents.tasks.llmindex_index.apply_async") as mock_update,
patch("paperless.views.vector_store_file_exists") as mock_exists,
):
mock_exists.return_value = True
self.client.patch(
f"{self.ENDPOINT}1/",
json.dumps({"llm_embedding_chunk_size": 512}),
content_type="application/json",
)
mock_update.assert_called_once()
self.assertEqual(mock_update.call_args.kwargs["kwargs"], {"rebuild": True})
def test_update_llm_context_size_triggers_rebuild(self) -> None:
config = ApplicationConfiguration.objects.first()
assert config is not None
config.ai_enabled = True
config.llm_embedding_backend = "openai-like"
config.llm_context_size = 8192
config.save()
with (
patch("documents.tasks.llmindex_index.apply_async") as mock_update,
patch("paperless.views.vector_store_file_exists") as mock_exists,
):
mock_exists.return_value = True
self.client.patch(
f"{self.ENDPOINT}1/",
json.dumps({"llm_context_size": 4096}),
content_type="application/json",
)
mock_update.assert_called_once()
self.assertEqual(mock_update.call_args.kwargs["kwargs"], {"rebuild": True})
def test_update_llm_embedding_model_triggers_rebuild(self) -> None:
config = ApplicationConfiguration.objects.first()
assert config is not None
config.ai_enabled = True
config.llm_embedding_backend = "openai-like"
config.llm_embedding_model = "text-embedding-3-small"
config.save()
with patch("documents.tasks.llmindex_index.apply_async") as mock_update:
self.client.patch(
f"{self.ENDPOINT}1/",
json.dumps({"llm_embedding_model": "text-embedding-3-large"}),
content_type="application/json",
)
mock_update.assert_called_once()
self.assertEqual(mock_update.call_args.kwargs["kwargs"], {"rebuild": True})
def test_enable_ai_index_with_config_change_triggers_rebuild(self) -> None:
config = ApplicationConfiguration.objects.first()
assert config is not None
config.ai_enabled = False
config.llm_embedding_backend = "openai-like"
config.llm_embedding_model = "text-embedding-3-small"
config.save()
with (
patch("documents.tasks.llmindex_index.apply_async") as mock_update,
patch("paperless.views.vector_store_file_exists") as mock_exists,
):
mock_exists.return_value = True
self.client.patch(
f"{self.ENDPOINT}1/",
json.dumps(
{
"ai_enabled": True,
"llm_embedding_model": "text-embedding-3-large",
},
),
content_type="application/json",
)
mock_update.assert_called_once()
self.assertEqual(mock_update.call_args.kwargs["kwargs"], {"rebuild": True})
@override_settings(LLM_ALLOW_INTERNAL_ENDPOINTS=False)
def test_update_llm_endpoint_blocks_internal_endpoint_when_disallowed(self) -> None:
response = self.client.patch(