Find answers from the community

Updated 2 years ago

I have no idea what I am doing But I am

I have no idea what I am doing; But I am trying to upload a file from nodejs to python fastapi, and create a qdrant index of it and place it in qdrant. And query the index and return an answer.

But it only returns -1 for the query.

I am using docker compose, and I figure I have loads of errors and it cant connect to qdrant or something like that. If anyone wants to take a glance.
Plain Text
import qdrant_client
client = qdrant_client.QdrantClient(
    host="qdrant"  # qdrant is the name of the docker container
)

@app.post("/upload")
async def upload_file(file: UploadFile = File(...)):
    uniqueid = uuid.uuid4()
    os.makedirs(f"files/{uniqueid}/", exist_ok=True)
    file_location = f"files/{uniqueid}/{file.filename}"
    with open(file_location, "wb+") as file_object:
        file_object.write(file.file.read())
    documents = SimpleDirectoryReader(f"files/{uniqueid}/").load_data()
    print(documents)
    index = GPTQdrantIndex(documents, collection_name=uniqueid, client=client)
    response = index.query(
        "Jeg har lyst til Γ₯ dra pΓ₯ ferie, kan jeg bruke firmahyttene?")
    shutil.rmtree(f"files/{uniqueid}/")
    return {"info": f"file '{file.filename}' successully indexed in Qdrant", "data":  response}


Plain Text
version: "3.8"
networks:
  app-tier:
    driver: bridge
services:
  fastapi:
    build: ./fastapi
    expose:
      - "5000"
    ports:
      - "5000:5000"  
    environment:
      - QDRANT_HOST=qdrant
    depends_on:
      - qdrant  
    networks:
      - app-tier   
    volumes:
      - ./fastapi:/app:Z
  sveltekit:
    build: ./sveltekit
    ports:
      - 3000:3000    
    networks:
      - app-tier    
    depends_on:
      - fastapi
    volumes:
      - ./sveltekit:/app:Z
    environment:
      - VITE_BACKEND_URL=http://localhost:5000
  qdrant:
    image: qdrant/qdrant:v0.10.1
    #    mem_limit: 450m
    ports:
      - 6333:6333
    volumes:
      - ./data/qdrant_storage:/qdrant/storage

    networks:
      - app-tier 
Attachments
image.png
image.png
image.png
image.png
d
L
.
49 comments
It just returns;
Attachment
image.png
You might need to cast the response as a string in the return? Not sure with FastAPI

You might also want to check if the client object has some sort of connection Check function that you can log the result of
Think there might be some async issues or something, doesn't work making a simple vector index either, so think I'll try pulling generation out in its own function.
I wonder if fastAPI is timing out the function? It's a little weird it used the 204 response code (then again, not 100% sure how fast api decides the code lol)
If I remove the index part it's really fast, and documents work. In the instant I introduce index, it halts, gotta get the kids to bed and grind further πŸ™‚
Haha nice, narrowed it down! πŸ’ͺ
@Logan M Oki, it looks like it worked when I created a new async function for the ingestion part, weird πŸ˜„ no idea how Python works, all new to me ^^
Haha I'm a little unfamiliar with pythons async stuff too, very weird. Glad it works! πŸ˜€
So this, worked. Oh well, lets get qdrant working ^^
Attachment
image.png
Yeah, everything worked out smoothly with qdrant after that. It also looked like the answer was alot better from qdrant than from simplevector, how about that
Ahhh nice! I'm guess qdrant might be using some different techniques for similarity matching? πŸ‘€
Its werid, i get a slightly different answer each upload. Even tho temp i 0 - so there is some magic going on there
Have to do some testing
Atleast its working ^^
And the 204 response was stupid, that was not from fastapi, but me trying to return bogus data in sveltekit πŸ˜„
I have a server side action that posts to fastapi, and it returns the backend data to front-end. And I forgot to do "await return.json()" and just did return πŸ™‚
Ohhhh that makes sense! Good catch!
next issue, how do I query with vectors, thats a big WTF with the QdrantReader πŸ˜„
Query with vectors?
To get the index from the qdrant db, query vectors
Yeah, I just thought I could get the data straight from the qdrant db and not have to save and load from file. Because this would just be the same as doing simple vector?
You can save and load still, but it's saving much less info.

When you load, just pass it an empty array instead of your documents, along with the qdrant info
Then it makes sense πŸ˜„ tnx for info!
First query after index is good, when I reload the index, I get some weird answers, like major hallucinations.
Hallucinations with the same query?
Maybe check response.source_nodes to make sure it's actually using the qdrant index
@Logan M Yeah, thans for that!

Doesn't look quite right πŸ˜„
Attachment
image.png
Uh oh haha πŸ˜… that looks like a text encoding issue somehow
My guess is qdrant is encoding with something other than utf8? πŸ€”
I found the issue - it was my lumpy fingers. I cleaned the filename and it was name-pdf so it didnt understand it was a pdf and parsed it as a binary file πŸ˜„

But atleast I am here now! So now I can get working ^^
Tnx for putting me in the right direction ^^
my cleaned vs not file πŸ˜„
That's what I get for not knowing enough python ^^
Still gives bad answers tho, maybe I have to add some gpt-4 magic to the mix
Glad it's working at least! πŸ’ͺπŸ’ͺ
Yeah, its getting there ^^
Thinking Ill release an open sournce full working stack of Gunicorn, Uvicorn, Fastapi, Qdrant, Sveltekit, Docker compose when I get it up and running ^^
Nice, do it! That would be an awesome resource.

If you want, you could add it to the starter pack (currently at 82 stars πŸ˜‰)

Totally cool if not though!
Maybe better, I am bad at facilitating that stuff anyways ^^ It has more stars than my top github project ^^
Jerry has (kindly) tweeted out the repo out a few times, which helps with the getting it noticed haha

I'm sure he can give you a shout out too for contributing it πŸ’ͺ
Yeah, thats pretty nice πŸ™‚
@dagthomas did you get uvicorn playing nice w/ llamaindex? I seem to be playing whackamole between the different components from llamaindex when using uvloop
I think it's pretty difficult to use uvloop. I always set the loop type to be asyncio when using fastapi
maybe someday nest_asyncio() will support uvloop :PSadge:
Add a reply
Sign up and join the conversation on Discord