Skip to content

Commit 755d00f

Browse files
committed
Refactor Postgres connector imports and update data model annotations
1 parent 71e3d30 commit 755d00f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

semantic-kernel/concepts/vector-store-connectors/out-of-the-box-connectors/postgres-connector.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ You can pass a `psycopg_pool` [AsyncConnectionPool](https://www.psycopg.org/psyc
346346
or use the `PostgresSettings` to create a connection pool from environment variables.
347347

348348
```python
349-
from semantic_kernel.connectors.memory.postgres import PostgresStore, PostgresSettings
349+
from semantic_kernel.connectors.postgres import PostgresStore, PostgresSettings
350350

351351
settings = PostgresSettings()
352352

@@ -363,9 +363,9 @@ You can also create a collection directly. The Collection itself is a context ma
363363
in a connection pool, the collection will create one using the `PostgresSettings` class.
364364

365365
```python
366-
from semantic_kernel.connectors.memory.postgres import PostgresCollection
366+
from semantic_kernel.connectors.postgres import PostgresCollection
367367

368-
collection = PostgresCollection(collection_name="skhotels", data_model_type=Hotel)
368+
collection = PostgresCollection(collection_name="skhotels", record_type=Hotel)
369369
async with collection: # This will create a connection pool using PostgresSettings
370370
...
371371
```
@@ -381,33 +381,33 @@ into a `dict` that can be serialized to Postgres rows.
381381
- The data model properties annotated as vectors will be mapped to a table column that has the pgvector `VECTOR` type in Postgres.
382382

383383
```python
384+
from typing import Annotated
384385
from pydantic import BaseModel
385386

386-
from semantic_kernel.connectors.memory.postgres import PostgresCollection
387-
from semantic_kernel.data import (
387+
from semantic_kernel.connectors.postgres import PostgresCollection
388+
from semantic_kernel.data.vector import (
388389
DistanceFunction,
389390
IndexKind,
390-
VectorStoreRecordDataField,
391-
VectorStoreRecordKeyField,
392-
VectorStoreRecordVectorField,
391+
VectorStoreField,
393392
vectorstoremodel,
394393
)
395394

396395
@vectorstoremodel
397396
class Hotel(BaseModel):
398-
hotel_id: Annotated[int, VectorStoreRecordKeyField()]
399-
hotel_name: Annotated[str, VectorStoreRecordDataField()]
400-
hotel_description: Annotated[str, VectorStoreRecordDataField(has_embedding=True, embedding_property_name="hotel_description_embedding")]
397+
hotel_id: Annotated[int, VectorStoreField("key")]
398+
hotel_name: Annotated[str, VectorStoreField("data")]
399+
hotel_description: Annotated[str, VectorStoreField("data")]
401400
hotel_description_embedding: Annotated[
402401
list[float] | None,
403-
VectorStoreRecordVectorField(
404-
index_kind=IndexKind.HNSW,
402+
VectorStoreField(
403+
"vector",
405404
dimensions=4,
405+
index_kind=IndexKind.HNSW,
406406
distance_function=DistanceFunction.COSINE_SIMILARITY,
407407
),
408408
] = None
409409

410-
collection = PostgresCollection(collection_name="Hotels", data_model_type=Hotel)
410+
collection = PostgresCollection(collection_name="Hotels", record_type=Hotel)
411411

412412
async with collection:
413413
await collection.create_collection_if_not_exists()
@@ -519,7 +519,7 @@ class AsyncEntraConnection(AsyncConnection):
519519
You can use the custom connection class with the `PostgresSettings.get_connection_pool` method to create a connection pool.
520520

521521
```python
522-
from semantic_kernel.connectors.memory.postgres import PostgresSettings, PostgresStore
522+
from semantic_kernel.connectors.postgres import PostgresSettings, PostgresStore
523523

524524

525525
pool = await PostgresSettings().create_connection_pool(connection_class=AsyncEntraConnection)

0 commit comments

Comments
 (0)