Home > OS >  How to add document for search in marqo
How to add document for search in marqo

Time:10-28

i recently started using the marqo library and i am trying to add document so that marqo can search and return the relevant part of the document but i keep getting error when i run the the code.

i used the

add_document() 

method and i pass the document as a string for search but it returns an error. Here is what my code look like;

import marqo

DOCUMENT = 'the document'

mq = marqo.Client(url='http://localhost:8882')

mq.index("my-first-index").add_documents(DOCUMENT)


and when i run it i get a

 MarqoWebError

CodePudding user response:

you are getting the error because the add_document() method takes a list of python dictionaries as an argument not a string, so you are to pass the document as a value to any key you assign to it. But it is advisable to add a title and also an id for later referencing. Here is what i mean;

mq.index("my-first-index").add_documents([
    {
        "Title": the_title_of_your_document,
        "Description": your_document,
        "_id": your_id,
    }]
)

the id can be any string of your choice. You can add as many dictionaries as you want to the list, each dictionary represents a document.

CodePudding user response:

I think the documents need to be a list of dicts. See here https://marqo.pages.dev/API-Reference/documents/

  • Related