Skip to content

Commit fff3445

Browse files
committed
update readme with latest changes
1 parent 411d60b commit fff3445

1 file changed

Lines changed: 64 additions & 17 deletions

File tree

README.md

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,76 @@ You can install the client in your PHP project using composer:
1616
composer require hkulekci/qdrant
1717
```
1818

19-
An example to create a collection :
19+
### Connecting to Qdrant
2020

2121
```php
22-
use Qdrant\Endpoints\Collections;
23-
use Qdrant\Http\GuzzleClient;
24-
use Qdrant\Models\Request\CreateCollection;
25-
use Qdrant\Models\Request\VectorParams;
26-
2722
include __DIR__ . "/../vendor/autoload.php";
2823
include_once 'config.php';
2924

30-
$config = new \Qdrant\Config(QDRANT_HOST);
25+
use Qdrant\Config;
26+
use Qdrant\Http\Builder;
27+
28+
$config = new Config(QDRANT_HOST);
3129
$config->setApiKey(QDRANT_API_KEY);
3230

33-
$client = new Qdrant(new GuzzleClient($config));
31+
$transport = (new Builder())->build($config);
32+
$client = new Qdrant($transport);
33+
```
34+
35+
### Creating a Collection
36+
37+
```php
38+
use Qdrant\Endpoints\Collections;
39+
use Qdrant\Models\Request\CreateCollection;
40+
use Qdrant\Models\Request\VectorParams;
3441

3542
$createCollection = new CreateCollection();
36-
$createCollection->addVector(new VectorParams(1024, VectorParams::DISTANCE_COSINE), 'image');
37-
$response = $client->collections('images')->create($createCollection);
43+
$createCollection->addVector(new VectorParams(1536, VectorParams::DISTANCE_COSINE), 'content');
44+
$response = $client->collections('contents')->create($createCollection);
3845
```
3946

40-
So now, we can insert a point :
47+
### Inserting Points Into Collection
4148

4249
```php
4350
use Qdrant\Models\PointsStruct;
4451
use Qdrant\Models\PointStruct;
4552
use Qdrant\Models\VectorStruct;
4653

54+
$openai = OpenAI::client(OPENAI_API_KEY);
55+
56+
$query = 'sustainable agricultural startups';
57+
$response = $openai->embeddings()->create([
58+
'model' => 'text-embedding-ada-002',
59+
'input' => $query,
60+
]);
61+
$embedding = array_values($response->embeddings[0]->embedding);
62+
4763
$points = new PointsStruct();
4864
$points->addPoint(
4965
new PointStruct(
5066
(int) $imageId,
51-
new VectorStruct($data['embeddings'][0], 'image'),
67+
new VectorStruct($embedding, 'content'),
5268
[
5369
'id' => 1,
5470
'meta' => 'Meta data'
5571
]
5672
)
5773
);
58-
$client->collections('images')->points()->upsert($points);
74+
$client->collections('contents')->points()->upsert($points);
5975
```
6076

61-
While upsert data, if you want to wait for upsert to actually happen, you can use query paramaters:
77+
### Wait for Acknowledges
6278

63-
```
64-
$client->collections('images')->points()->upsert($points, ['wait' => 'true']);
79+
While upsert data, if you want to wait for upsert to actually happen, you can use query parameters:
80+
81+
```php
82+
$client->collections('contents')->points()->upsert($points, ['wait' => 'true']);
6583
```
6684

6785
You can check for more parameters : https://qdrant.github.io/qdrant/redoc/index.html#tag/points/operation/upsert_points
6886

87+
### Search on Points
88+
6989
Search with a filter :
7090

7191
```php
@@ -87,5 +107,32 @@ $searchRequest = (new SearchRequest(new VectorStruct($embedding, 'elev_pitch')))
87107
])
88108
->setWithPayload(true);
89109

90-
$response = $client->collections('images')->points()->search($searchRequest);
110+
$response = $client->collections('contents')->points()->search($searchRequest);
91111
```
112+
113+
### Search on Points with OpenAI Embeddings
114+
115+
```php
116+
$openai = OpenAI::client(OPENAI_API_KEY);
117+
118+
$query = 'lorem ipsum dolor sit amed';
119+
$response = $openai->embeddings()->create([
120+
'model' => 'text-embedding-ada-002',
121+
'input' => $query,
122+
]);
123+
$embedding = array_values($response->embeddings[0]->embedding);
124+
125+
$searchRequest = (new SearchRequest(new VectorStruct($embedding, 'content')))
126+
->setLimit(10)
127+
->setParams([
128+
'hnsw_ef' => 128,
129+
'exact' => false,
130+
])
131+
->setWithPayload(true);
132+
133+
$response = $client->collections('contents')->points()->search($searchRequest);
134+
135+
foreach ($response['result'] as $item) {
136+
echo $item['score'] . ';' . $item['payload']['id'] . ';' . $item['payload']['meta_data'] . PHP_EOL;
137+
}
138+
```

0 commit comments

Comments
 (0)