index=index_name, body={ "_source": {"exclude": ["body_chunk_embedding"]}, "query": { "hybrid": { "queries": [ {"match": {"body_chunk": {"query": query,}}}, {"nested": { "score_mode": "max", "path": "body_chunk_embedding", "query": { "neural": { "body_chunk_embedding.knn": { "query_text": query, "model_id": titan_model_id, }}},}},],}}, "ext": { "rerank": {"query_context": {"query_text": query,},}, "generative_qa_parameters": { "llm_model": "litellm", "llm_question": query, "context_size": 4, },},}, params={"search_pipeline": "hybrid-rerank-search-pipeline"}, ) 25 context = list(map(lambda x: x["_source"], response["hits"]["hits"])) for tmp in context: del tmp["body_chunk"] return { "answer": response["ext"]["retrieval_augmented_generation"]["answer"], "context": context, } By defining a search pipeline, you can get RAG results just by calling the search API.