Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 1425851

Browse files
authored
feat: add pinecone store support (#28)
1 parent b2802ee commit 1425851

File tree

4 files changed

+70
-17
lines changed

4 files changed

+70
-17
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,27 @@ llm_chain:
4040
original_embeddings:
4141
platform: 'openai'
4242
stores:
43-
chroma_db:
44-
engine: 'chroma-db'
45-
collection_name: '%env(CHROMA_COLLECTION)%'
4643
azure_search:
4744
engine: 'azure-search'
48-
api_key: '%env(AZURE_SEARCH_KEY)%'
45+
api_key: '%env(AZURE_SEARCH_KEY)%'
4946
endpoint: '%env(AZURE_SEARCH_ENDPOINT)%'
50-
index_name: '%env(AZURE_SEARCH_INDEX)%'
47+
index_name: '%env(AZURE_SEARCH_INDEX)%'
5148
api_version: '2024-07-01'
49+
chroma_db:
50+
engine: 'chroma-db'
51+
collection_name: '%env(CHROMA_COLLECTION)%'
5252
mongodb:
5353
engine: 'mongodb'
5454
database_name: '%env(MONGODB_DATABASE)%'
5555
collection_name: '%env(MONGODB_COLLECTION)%'
5656
index_name: '%env(MONGODB_INDEX)%'
5757
vector_field_name: 'vector'
5858
bulk_write: false
59+
pinecone:
60+
engine: 'pinecone'
61+
namespace: 'partition'
62+
filter: { 'key' : 'value' }
63+
top_k: 5
5964
```
6065
6166
## Usage

src/DependencyInjection/Configuration.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,23 @@ public function getConfigTreeBuilder(): TreeBuilder
5252
->useAttributeAsKey('name')
5353
->arrayPrototype()
5454
->children()
55-
->enumNode('engine')->values(['chroma-db', 'azure-search', 'mongodb'])->isRequired()->end()
56-
->scalarNode('collection_name')->end()
57-
->scalarNode('api_key')->end()
58-
->scalarNode('endpoint')->end()
55+
->enumNode('engine')->values(['azure-search', 'chroma-db', 'mongodb', 'pinecone'])->isRequired()->end()
56+
// Azure AI Search & MongoDB
5957
->scalarNode('index_name')->end()
58+
// Azure AI Search
59+
->scalarNode('api_key')->end()
6060
->scalarNode('api_version')->end()
61+
->scalarNode('endpoint')->end()
62+
// ChromaDB & MongoDB
63+
->scalarNode('collection_name')->end()
64+
// MongoDB
6165
->scalarNode('database_name')->end()
62-
->scalarNode('vector_field_name')->end()
6366
->booleanNode('bulk_write')->end()
67+
->scalarNode('vector_field_name')->end()
68+
// Pinecone
69+
->arrayNode('filter')->end()
70+
->scalarNode('namespace')->end()
71+
->scalarNode('top_k')->end()
6472
->end()
6573
->end()
6674
->end()

src/DependencyInjection/LlmChainExtension.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore;
1515
use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore;
1616
use PhpLlm\LlmChain\Store\MongoDB\Store as MongoDBStore;
17+
use PhpLlm\LlmChain\Store\Pinecone\Store as PineconeStore;
1718
use PhpLlm\LlmChain\Store\StoreInterface;
1819
use PhpLlm\LlmChain\Store\VectorStoreInterface;
1920
use PhpLlm\LlmChain\ToolBox\AsTool;
@@ -148,13 +149,6 @@ private function processEmbeddingsConfig(string $name, array $embeddings, Contai
148149
*/
149150
private function processStoreConfig(string $name, array $stores, ContainerBuilder $container): void
150151
{
151-
if ('chroma-db' === $stores['engine']) {
152-
$definition = new ChildDefinition(ChromaDBStore::class);
153-
$definition->replaceArgument('$collectionName', $stores['collection_name']);
154-
155-
$container->setDefinition('llm_chain.store.'.$name, $definition);
156-
}
157-
158152
if ('azure-search' === $stores['engine']) {
159153
$definition = new ChildDefinition(AzureSearchStore::class);
160154
$definition
@@ -166,6 +160,13 @@ private function processStoreConfig(string $name, array $stores, ContainerBuilde
166160
$container->setDefinition('llm_chain.store.'.$name, $definition);
167161
}
168162

163+
if ('chroma-db' === $stores['engine']) {
164+
$definition = new ChildDefinition(ChromaDBStore::class);
165+
$definition->replaceArgument('$collectionName', $stores['collection_name']);
166+
167+
$container->setDefinition('llm_chain.store.'.$name, $definition);
168+
}
169+
169170
if ('mongodb' === $stores['engine']) {
170171
$definition = new ChildDefinition(MongoDBStore::class);
171172
$definition
@@ -177,5 +178,15 @@ private function processStoreConfig(string $name, array $stores, ContainerBuilde
177178

178179
$container->setDefinition('llm_chain.store.'.$name, $definition);
179180
}
181+
182+
if ('pinecone' === $stores['engine']) {
183+
$definition = new ChildDefinition(PineconeStore::class);
184+
$definition
185+
->replaceArgument('$namespace', $stores['namespace'] ?? null)
186+
->replaceArgument('$filter', $stores['filter'] ?? [])
187+
->replaceArgument('$topK', $stores['top_k'] ?? 3);
188+
189+
$container->setDefinition('llm_chain.store.'.$name, $definition);
190+
}
180191
}
181192
}

src/Resources/config/services.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
66

77
use PhpLlm\LlmChain\Chain;
8+
use PhpLlm\LlmChain\Chain\InputProcessor;
9+
use PhpLlm\LlmChain\Chain\OutputProcessor;
810
use PhpLlm\LlmChain\DocumentEmbedder;
911
use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
1012
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
@@ -14,6 +16,11 @@
1416
use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore;
1517
use PhpLlm\LlmChain\Store\ChromaDB\Store as ChromaDBStore;
1618
use PhpLlm\LlmChain\Store\MongoDB\Store as MongoDBStore;
19+
use PhpLlm\LlmChain\Store\Pinecone\Store as PineconeStore;
20+
use PhpLlm\LlmChain\StructuredOutput\ChainProcessor as StructureOutputProcessor;
21+
use PhpLlm\LlmChain\StructuredOutput\ResponseFormatFactory;
22+
use PhpLlm\LlmChain\StructuredOutput\SchemaFactory;
23+
use PhpLlm\LlmChain\ToolBox\ChainProcessor as ToolProcessor;
1724
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
1825
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1926
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -26,9 +33,17 @@
2633
->defaults()
2734
->autowire()
2835
->autoconfigure()
36+
->instanceof(InputProcessor::class)
37+
->tag('llm_chain.chain.input_processor')
38+
->instanceof(OutputProcessor::class)
39+
->tag('llm_chain.chain.output_processor')
2940

3041
// high level feature
3142
->set(Chain::class)
43+
->args([
44+
'$inputProcessor' => tagged_iterator('llm_chain.chain.input_processor'),
45+
'$outputProcessor' => tagged_iterator('llm_chain.chain.output_processor'),
46+
])
3247
->set(DocumentEmbedder::class)
3348

3449
// platforms
@@ -81,6 +96,19 @@
8196
'$vectorFieldName' => abstract_arg('The name of the field int the index that contains the vector'),
8297
'$bulkWrite' => abstract_arg('Use bulk write operations'),
8398
])
99+
->set(PineconeStore::class)
100+
->abstract()
101+
->args([
102+
'$namespace' => abstract_arg('Namespace of index'),
103+
'$filter' => abstract_arg('Filter for metadata'),
104+
'$topK' => abstract_arg('Number of results to return'),
105+
])
106+
107+
// structured output
108+
->set(ResponseFormatFactory::class)
109+
->set(SchemaFactory::class)
110+
->factory([SchemaFactory::class, 'create'])
111+
->set(StructureOutputProcessor::class)
84112

85113
// tools
86114
->set(ToolBox::class)
@@ -90,6 +118,7 @@
90118
->alias(ToolBoxInterface::class, ToolBox::class)
91119
->set(ToolAnalyzer::class)
92120
->set(ParameterAnalyzer::class)
121+
->set(ToolProcessor::class)
93122

94123
// profiler
95124
->set(DataCollector::class)

0 commit comments

Comments
 (0)