0]); $chain = VectorDBQA::fromChainType( $llm, 'stuff', null, array_merge(['vectorstore' => $this->vectorStore], $additionalParams) ); return $chain(['query' => $question])[$chain->outputKey]; } /** * Query the vectorstore and get back the answer and source documents. * * @param string $question * @param BaseLLM|null $llm * @param array $additionalParams * * @return array */ public function queryWithSources(string $question, ?BaseLLM $llm = null, array $additionalParams = []): array { $llm = $llm ?? new OpenAI(['temperature' => 0]); $chain = VectorDBQA::fromChainType( $llm, 'stuff', null, array_merge(['vectorstore' => $this->vectorStore, 'return_source_documents' => true], $additionalParams) ); //error_log(print_r($chain)); $result = $chain(['query' => $question]); return [ 'query' => $question, 'result' => $result[$chain->outputKey], 'source_documents' => $result['source_documents'] ?? [], ]; } }