Skip to content

馃煛 [QUALITY] RAG context has no limits or diversity聽#17

Closed

Description

@FullFran

Problem

Current context building:

context = '\n'.join([
    f'--- Documento: {m.document_title} ---\n{m.chunk.content}'
    for m in matches
])

Issues:

  • No token/length limit (context explosion)
  • No diversity (might get 5 chunks from same doc)
  • No metadata for citation (chunk_index, source_ref)

Solution

Create ContextBuilder in application layer:

class ContextBuilder:
    def __init__(self, max_tokens: int = 4000, max_per_doc: int = 2):
        ...
    
    def build(self, hits: List[SearchHit]) -> tuple[str, List[Citation]]:
        '''Build context with diversity and limits.'''

Acceptance Criteria

  • Token/character limit enforced
  • Max chunks per document
  • Citations returned for transparency

Activity

  1. FullFran commented on Jan 26, 2026

    @FullFran
    OwnerAuthor

    Resuelto. Hay un ContextBuilder en con l铆mites de tama帽o (max_chars) y diversidad (max_per_document), adem谩s de citas con chunk_index y fuente. lo usa para construir el contexto. Criterios cubiertos, cierro la issue.

  2. FullFran commented on Jan 26, 2026

    @FullFran
    OwnerAuthor

    Corrijo comentario anterior (el backtick se interpret贸 en shell).

    Resuelto. Hay un ContextBuilder en src/services/context_builder.py con l铆mites de tama帽o (max_chars) y diversidad (max_per_document), adem谩s de citas con chunk_index y fuente. src/services/rag_service.py lo usa para construir el contexto. Criterios cubiertos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions