Skip to content

Commit 12aefbe

Browse files
committed
feat: add support for azure ai search store
1 parent d3b078f commit 12aefbe

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

README.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,42 @@ composer require php-llm/llm-chain-bundle:@dev php-llm/llm-chain:@dev
1313
```yaml
1414
# config/packages/llm_chain.yaml
1515
llm_chain:
16-
runtimes:
17-
azure_gpt:
18-
type: 'azure'
19-
base_url: '%env(AZURE_OPENAI_BASEURL)%'
20-
deployment: '%env(AZURE_OPENAI_GPT)%'
21-
api_key: '%env(AZURE_OPENAI_KEY)%'
22-
version: '%env(AZURE_OPENAI_VERSION)%'
23-
azure_embeddings:
24-
type: 'azure'
25-
base_url: '%env(AZURE_OPENAI_BASEURL)%'
26-
deployment: '%env(AZURE_OPENAI_EMBEDDINGS)%'
27-
api_key: '%env(AZURE_OPENAI_KEY)%'
28-
version: '%env(AZURE_OPENAI_VERSION)%'
29-
openai:
30-
type: 'openai'
31-
api_key: '%env(OPENAI_API_KEY)%'
32-
llms:
33-
azure_gpt:
34-
runtime: 'azure_gpt'
35-
original_gpt:
36-
runtime: 'openai'
37-
embeddings:
38-
azure_embeddings:
39-
runtime: 'azure_embeddings'
40-
original_embeddings:
41-
runtime: 'openai'
16+
runtimes:
17+
azure_gpt:
18+
type: 'azure'
19+
base_url: '%env(AZURE_OPENAI_BASEURL)%'
20+
deployment: '%env(AZURE_OPENAI_GPT)%'
21+
api_key: '%env(AZURE_OPENAI_KEY)%'
22+
version: '%env(AZURE_OPENAI_VERSION)%'
23+
azure_embeddings:
24+
type: 'azure'
25+
base_url: '%env(AZURE_OPENAI_BASEURL)%'
26+
deployment: '%env(AZURE_OPENAI_EMBEDDINGS)%'
27+
api_key: '%env(AZURE_OPENAI_KEY)%'
28+
version: '%env(AZURE_OPENAI_VERSION)%'
29+
openai:
30+
type: 'openai'
31+
api_key: '%env(OPENAI_API_KEY)%'
32+
llms:
33+
azure_gpt:
34+
runtime: 'azure_gpt'
35+
original_gpt:
36+
runtime: 'openai'
37+
embeddings:
38+
azure_embeddings:
39+
runtime: 'azure_embeddings'
40+
original_embeddings:
41+
runtime: 'openai'
42+
stores:
43+
chroma_db:
44+
type: 'chroma-db'
45+
collection_name: '%env(CHROMA_COLLECTION)%'
46+
azure_search:
47+
type: 'azure-search'
48+
api_key: '%env(AZURE_SEARCH_KEY)%'
49+
endpoint: '%env(AZURE_SEARCH_ENDPOINT)%'
50+
index_name: '%env(AZURE_SEARCH_INDEX)%'
51+
api_version: '2024-07-01'
4252
```
4353
4454
## Usage

src/DependencyInjection/Configuration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ public function getConfigTreeBuilder(): TreeBuilder
5252
->useAttributeAsKey('name')
5353
->arrayPrototype()
5454
->children()
55-
->scalarNode('engine')->isRequired()->end()
55+
->enumNode('engine')->values(['chroma-db', 'azure-search'])->isRequired()->end()
5656
->scalarNode('collection_name')->end()
57+
->scalarNode('api_key')->end()
58+
->scalarNode('endpoint')->end()
59+
->scalarNode('index_name')->end()
60+
->scalarNode('api_version')->end()
5761
->end()
5862
->end()
5963
->end()

src/DependencyInjection/LlmChainExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PhpLlm\LlmChain\OpenAI\Runtime;
1212
use PhpLlm\LlmChain\OpenAI\Runtime\Azure as AzureRuntime;
1313
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI as OpenAIRuntime;
14+
use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore;
1415
use PhpLlm\LlmChain\Store\ChromaDb\Store as ChromaDbStore;
1516
use PhpLlm\LlmChain\Store\StoreInterface;
1617
use PhpLlm\LlmChain\Store\VectorStoreInterface;
@@ -122,5 +123,16 @@ private function processStoreConfig(string $name, mixed $stores, ContainerBuilde
122123

123124
$container->setDefinition('llm_chain.store.'.$name, $definition);
124125
}
126+
127+
if ('azure-search' === $stores['engine']) {
128+
$definition = new ChildDefinition(AzureSearchStore::class);
129+
$definition
130+
->replaceArgument('$endpointUrl', $stores['endpoint'])
131+
->replaceArgument('$apiKey', $stores['api_key'])
132+
->replaceArgument('$indexName', $stores['index_name'])
133+
->replaceArgument('$apiVersion', $stores['api_version']);
134+
135+
$container->setDefinition('llm_chain.store.'.$name, $definition);
136+
}
125137
}
126138
}

src/Resources/config/services.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
use PhpLlm\LlmChain\OpenAI\Runtime;
1212
use PhpLlm\LlmChain\OpenAI\Runtime\Azure as AzureRuntime;
1313
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI as OpenAIRuntime;
14-
use PhpLlm\LlmChain\RetrievalChain;
14+
use PhpLlm\LlmChain\Store\Azure\SearchStore;
1515
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
1616
use PhpLlm\LlmChain\ToolBox\Registry;
1717
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1818
use PhpLlm\LlmChain\ToolChain;
19+
use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore;
1920
use PhpLlm\LlmChain\Store\ChromaDb\Store as ChromaDbStore;
2021

2122
return static function (ContainerConfigurator $container) {
@@ -26,7 +27,6 @@
2627

2728
// chains
2829
->set(Chat::class)
29-
->set(RetrievalChain::class)
3030
->set(ToolChain::class)
3131

3232
// runtimes
@@ -57,6 +57,14 @@
5757
])
5858

5959
// stores
60+
->set(AzureSearchStore::class)
61+
->abstract()
62+
->args([
63+
'$endpointUrl' => abstract_arg('Endpoint URL for Azure AI Search API'),
64+
'$apiKey' => abstract_arg('API key for Azure AI Search API'),
65+
'$indexName' => abstract_arg('Name of Azure AI Search index'),
66+
'$apiVersion' => abstract_arg('API version for Azure AI Search API'),
67+
])
6068
->set(ChromaDbStore::class)
6169
->abstract()
6270
->args([

0 commit comments

Comments
 (0)