autogen.agentchat.contrib.rag.LlamaIndexQueryEngine
LlamaIndexQueryEngine
This engine leverages LlamaIndex’s VectorStoreIndex to efficiently index and retrieve documents, and generate an answer in response
to natural language queries. It use any LlamaIndex vector store.
By default the engine will use OpenAI’s GPT-4o model (use the llm
parameter to change that).
Initializes the LlamaIndexQueryEngine with the given vector store.
Name | Description |
---|---|
vector_store | Type: BasePydanticVectorStore |
llm | Type: ForwardRef(‘LLM’) | None Default: None |
file_reader_class | Type: type[‘SimpleDirectoryReader’] | None Default: None |
Instance Methods
add_docs
Add new documents to the underlying database and add to the index.
Name | Description |
---|---|
new_doc_dir | A dir of input documents that are used to create the records in database. Type: pathlib.Path | str | None Default: None |
new_doc_paths_or_urls | A sequence of input documents that are used to create the records in database. A document can be a Path to a file or a url. Type: Sequence[pathlib.Path | str] | None Default: None |
*args | Any additional arguments Type: Any |
**kwargs | Any additional keyword arguments Type: Any |
connect_db
Connect to the database.
It sets up the LlamaIndex storage and create an index from the existing vector store.
Name | Description |
---|---|
*args | Any additional arguments Type: Any |
**kwargs | Any additional keyword arguments Type: Any |
Type | Description |
---|---|
bool | bool: True if connection is successful |
init_db
Initialize the database with the input documents or records.
It takes the following steps:
1. Set up LlamaIndex storage context.
2. insert documents and build an index upon them.
Name | Description |
---|---|
new_doc_dir | a dir of input documents that are used to create the records in database. Type: pathlib.Path | str | None Default: None |
new_doc_paths_or_urls | A sequence of input documents that are used to create the records in database. A document can be a Path to a file or a url. Type: Sequence[pathlib.Path | str] | None Default: None |
*args | Any additional arguments Type: Any |
**kwargs | Any additional keyword arguments Type: Any |
Type | Description |
---|---|
bool | bool: True if initialization is successful |
query
Retrieve information from indexed documents by processing a query using the engine’s LLM.
Name | Description |
---|---|
question | A natural language query string used to search the indexed documents. Type: str |
Type | Description |
---|---|
str | A string containing the response generated by LLM. |