Not able to fetch files from a directory using llama-index and qdrant db

1.1k Views Asked by At

I am using qdrant db locally. My Folder is located on /home/komica/git/playbookhub/api directory name data in which I have a demo.txt file.

The issue is when I use to fetch this data directory by using llama-index query, I always get the error as Not Found / in my terminal.

Below is my method in which I use llama-index Please let me know what I am doing wrong here:

openai.api_key = settings.OPENAI_API_KEY

@require_GET
def query_documents(request):
    try:
        client = QdrantClient(":memory:")

        data_path = '/home/komica/git/playbookhub/api/data' 
        documents = SimpleDirectoryReader(data_path).load_data()

        vector_store = QdrantVectorStore(client=client, collection_name="customer_help")
        storage_context = StorageContext.from_defaults(vector_store=vector_store)

        index = GPTVectorStoreIndex.from_documents(documents, storage_context=storage_context)

        for document in documents:
            index.update(document)

        query_engine = index.as_query_engine()
        response = query_engine.query("What is her name?")

        return JsonResponse(response)
    except Exception as e:
        error_message = str(e)
        response = {
            'error': error_message
        }
        return JsonResponse(response, status=500)
1

There are 1 best solutions below

0
On

you may get the list of all files as data_file and set it as below.

data_file = ['/home/komica/git/playbookhub/api/datafile1', '/home/komica/git/playbookhub/api/datafile2' ]
documents = SimpleDirectoryReader(input_files=data_file).load_data()