AllAboutAI-YT / easy-local-rag

SuperEasy 100% Local RAG with Ollama + Email RAG
MIT License
675 stars 177 forks source link

hangs when generating embeddings on supplied vault.txt #14

Open pjbaron opened 4 months ago

pjbaron commented 4 months ago

WSL2, Windows 10 Pro, Ubuntu 22.04

The localrag.py script will hang indefinitely when processing the supplied vault.txt file.

The problem appears to be that the mxbai-embed-large model hangs when supplied with an empty line (which separate each of the first ~15 sentences in the vault.txt, after these lines, the sentence separators switch from CRLF CRLF to just LF and there are no more empty lines)

I have hack-patched it here with the code:

# Generate embeddings for the vault content using Ollama
print(NEON_GREEN + "Generating embeddings for the vault content..." + RESET_COLOR)
vault_embeddings = []
for content in vault_content:
    if (len(content.strip()) > 0):
        print(NEON_GREEN + ">" + content + RESET_COLOR)
        response = ollama.embeddings(model='mxbai-embed-large', prompt=content)
        vault_embeddings.append(response["embedding"])
    else:
        print(NEON_GREEN + "! skip empty line" + RESET_COLOR)
markmacumber commented 4 months ago

Thank you for this, I also noticed that the embeddings hung and didn't know why, good to know it was not something I did but how the embeddings model was behaving!

jwai99 commented 4 months ago

thank you this fixed my problem

vitorcalvi commented 3 months ago

Traceback (most recent call last): File "localrag.py", line 157, in response = ollama.embeddings(model='mxbai-embed-large', prompt=content) File "/opt/homebrew/anaconda3/envs/RAG2/lib/python3.8/site-packages/ollama/_client.py", line 198, in embeddings return self._request( File "/opt/homebrew/anaconda3/envs/RAG2/lib/python3.8/site-packages/ollama/_client.py", line 73, in _request raise ResponseError(e.response.text, e.response.status_code) from None ollama._types.ResponseError: failed to generate embedding

mr250624 commented 3 months ago

hey @vitorcalvi , I see the same error as you. Not really looked into it much but I found if you find the line that reads:

response = ollama.embeddings(model='mxbai-embed-large', prompt=content)

If I add a 'blank' line before it...it works. So change that one line in localrag.py to:

response = ollama.embeddings(model='mxbai-embed-large', prompt='')
response = ollama.embeddings(model='mxbai-embed-large', prompt=content)

Like I say I have no idea why and I havent looked into it. I was just debugging..and it worked :)