mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-26 21:39:43 +02:00
citations: consolidate prompts, retire eager path, refresh ADR
Rewrite the main-agent citation contract to a single [n] channel and sync the orphaned system_prompt_composer surface to match; drop stale [citation:chunk_id] / <chunk_index> references from dynamic_context and provider hints. Reuse the shared hybrid search in the deliverables report (citations omitted for now) and delete the orphaned report KB helper. Remove the dead eager KnowledgePriorityMiddleware wiring (knowledge_priority + stack) and its legacy browse test. Update ADR 0001 to reflect the cutover.
This commit is contained in:
parent
49d675c065
commit
ce15016533
20 changed files with 316 additions and 1127 deletions
|
|
@ -3,7 +3,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
|
@ -227,23 +226,6 @@ def patched_embed(monkeypatch):
|
|||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patched_shielded_session(async_engine, monkeypatch):
|
||||
"""Replace ``shielded_async_session`` in the knowledge_base module
|
||||
with one that yields sessions from the test engine."""
|
||||
test_maker = async_sessionmaker(async_engine, expire_on_commit=False)
|
||||
|
||||
@asynccontextmanager
|
||||
async def _test_shielded():
|
||||
async with test_maker() as session:
|
||||
yield session
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.agents.chat.multi_agent_chat.subagents.builtins.deliverables.tools.knowledge_base.shielded_async_session",
|
||||
_test_shielded,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Indexer test helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
"""Integration test: _browse_recent_documents returns docs of multiple types.
|
||||
|
||||
Exercises the browse path (degenerate-query fallback) with a real PostgreSQL
|
||||
database. Verifies that passing a list of document types correctly returns
|
||||
documents of all listed types -- the same ``.in_()`` SQL path used by hybrid
|
||||
search but through the browse/recency-ordered code path.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
async def test_browse_recent_documents_with_list_type_returns_both(
|
||||
committed_google_data, patched_shielded_session
|
||||
):
|
||||
"""_browse_recent_documents returns docs of all types when given a list."""
|
||||
from app.agents.chat.multi_agent_chat.subagents.builtins.deliverables.tools.knowledge_base import (
|
||||
_browse_recent_documents,
|
||||
)
|
||||
|
||||
space_id = committed_google_data["search_space_id"]
|
||||
|
||||
results = await _browse_recent_documents(
|
||||
search_space_id=space_id,
|
||||
document_type=["GOOGLE_DRIVE_FILE", "COMPOSIO_GOOGLE_DRIVE_CONNECTOR"],
|
||||
top_k=10,
|
||||
start_date=None,
|
||||
end_date=None,
|
||||
)
|
||||
|
||||
returned_types = set()
|
||||
for doc in results:
|
||||
doc_info = doc.get("document", {})
|
||||
dtype = doc_info.get("document_type")
|
||||
if dtype:
|
||||
returned_types.add(dtype)
|
||||
|
||||
assert "GOOGLE_DRIVE_FILE" in returned_types, (
|
||||
"Native Drive docs should appear in browse results"
|
||||
)
|
||||
assert "COMPOSIO_GOOGLE_DRIVE_CONNECTOR" in returned_types, (
|
||||
"Legacy Composio Drive docs should appear in browse results"
|
||||
)
|
||||
|
|
@ -86,9 +86,10 @@ class TestCompose:
|
|||
# Tools
|
||||
assert "<tools>" in prompt
|
||||
assert "</tools>" in prompt
|
||||
# Citations on by default
|
||||
# Citations on by default — the [n] / <retrieved_context> contract
|
||||
assert "<citation_instructions>" in prompt
|
||||
assert "[citation:chunk_id]" in prompt
|
||||
assert "<retrieved_context>" in prompt
|
||||
assert "[1][2]" in prompt
|
||||
|
||||
def test_team_visibility_uses_team_variants(self, fixed_today: datetime) -> None:
|
||||
prompt = compose_system_prompt(
|
||||
|
|
@ -116,9 +117,9 @@ class TestCompose:
|
|||
def test_citations_disabled_swaps_block(self, fixed_today: datetime) -> None:
|
||||
prompt_on = compose_system_prompt(today=fixed_today, citations_enabled=True)
|
||||
prompt_off = compose_system_prompt(today=fixed_today, citations_enabled=False)
|
||||
assert "Citations are DISABLED" in prompt_off
|
||||
assert "Citations are DISABLED" not in prompt_on
|
||||
assert "[citation:chunk_id]" in prompt_on
|
||||
assert "Citation markers are **disabled**" in prompt_off
|
||||
assert "Citation markers are **disabled**" not in prompt_on
|
||||
assert "<retrieved_context>" in prompt_on
|
||||
|
||||
def test_enabled_tool_filter_only_includes_listed_tools(
|
||||
self, fixed_today: datetime
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue