Write simple code for a RAG (retrieval-augmented generation) pipeline.
Asked in the L2 round stage. L2 for GenAI developer.
Implement rag_pipeline(documents, query, top_k). Tokenize text case-insensitively, retrieve documents by counting distinct query-token overlaps, preserve input order for ties, and return the selected documents joined with newline characters as a simple extractive answer. Return an empty string when no document matches.
def rag_pipeline(documents, query, top_k):