Unable to Retrieve Chat Responses from Multiple llama Indexes

I’m currently encountering an issue while attempting to retrieve chat responses from multiple indexes in my project. Here’s a brief overview of the situation:

Problem: Despite conducting thorough research, I haven’t found a suitable solution for fetching chat responses from multiple indexes simultaneously.

Objective: My goal is to efficiently collect chat responses from various indexes within my application to enhance the user experience.

Below is a snippet of the code I’m currently using to handle chat requests and create indexes:

async def handle_chat_request(request: Request, data: ChatData) -> StreamingResponse:
    if data.config.model in OLLAMA_MODELS:
        return await _ollama_chat(request, data)
    elif data.config.model in OPENAI_MODELS:
        return await _openai_chat(request, data)
    else:
        raise HTTPException(status_code=400, detail="Invalid Model Name.")
    
async def _openai_chat(request: Request, data: ChatData) -> StreamingResponse:
    print("Received an OpenAI chat request:", request, data)
    Settings.llm = OpenAI(model=data.config.model, temperature=0.2)
    Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
    return await _chat_stream(request, data)


async def _chat_stream(request: Request, data: ChatData) -> StreamingResponse:
    try:
        index = _get_or_create_index(data.config.model, data.datasource)
        chat_engine = index.as_chat_engine()
        response = chat_engine.stream_chat(data.message, [])

        async def event_generator():
            for token in response.response_gen:
                if await request.is_disconnected():
                    break
                yield convert_sse(token)
            yield convert_sse({"done": True})

        return StreamingResponse(
            event_generator(),
            media_type="text/event-stream",
        )
    except Exception as e:
        full_exception = traceback.format_exc()
        logger.error(f"{data.config.model} chat error: {e}n{40 * '~'} n{full_exception}")
        raise HTTPException(status_code=500, detail="Internal Server Error")

Initially, I attempted to combine multiple documents into a single index to address this challenge. However, this approach led to accuracy issues in the response. Refactoring is necessary to overcome this obstacle. Below is the code snippet illustrating the initial approach:

document1 = SimpleDirectoryReader(ds_data_dir).load_data()
document2 = generate_web_index("https://github.com")

index = VectorStoreIndex.from_documents(document1 + document2 , show_progress=True, 
                                        storage_context=StorageContext.from_defaults(),
                                        embed_model=Settings.embed_model)
index.storage_context.persist(ds_storage_dir)
def generate_web_index(website_url: str):
    return BeautifulSoupWebReader().load_data(urls=[website_url])

I’m seeking advice on how to improve this approach and handle multiple indexes effectively. Any insights or suggestions would be greatly appreciated.

Thank you.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật