Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up all the process #230

Open
gamingl1n32 opened this issue Nov 7, 2024 · 1 comment
Open

Speed up all the process #230

gamingl1n32 opened this issue Nov 7, 2024 · 1 comment

Comments

@gamingl1n32
Copy link

gamingl1n32 commented Nov 7, 2024

Hey,

Have the next code:

import os
from lightrag import LightRAG, QueryParam

WORKING_DIR = "./dickens"

from lightrag.utils import EmbeddingFunc
if not os.path.exists(WORKING_DIR):
    os.mkdir(WORKING_DIR)

from lightrag.llm import hf_model_complete, hf_embedding
from transformers import AutoModel, AutoTokenizer, AutoModelForPreTraining

rag = LightRAG(
    working_dir=WORKING_DIR,
    llm_model_func=hf_model_complete, 
    llm_model_name='RefalMachine/ruadapt_qwen2.5_3B_ext_u48_instruct_v4', 
    # Use Hugging Face embedding function
    embedding_func=EmbeddingFunc(
        embedding_dim=384,
        max_token_size=5000,
        func=lambda texts: hf_embedding(
            texts,
            tokenizer=AutoTokenizer.from_pretrained("sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"),
            embed_model=AutoModel.from_pretrained("sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
        )
    ),
)

with open("results\prompts\abstract_summary.txt", encoding="utf8") as f:
    rag.insert(f.read())


import time


start_time = time.perf_counter()
query = "<MY-QUESTION>"
result = rag.query(query, param=QueryParam(mode="local"))
end_time = time.perf_counter()

elapsed_time = end_time - start_time
print(f"Execution time: {elapsed_time:.6f} seconds")
print(query)
print("Answer: ")
print(result)

the time to create chunks for 1 document with 3483 word = 20 minutes
time to answer for some questions is from 15 secs to 1400 sec using local method

PC specs:
rtx 4060
16 ram
i5-12500H

any ideas to speed up?
my goal is to gen an correct answer iin ~20sec max

@LarFii
Copy link
Collaborator

LarFii commented Nov 12, 2024

For the insert, you can refer to #212. For queries, our tests generally complete within 20 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants