Skip to content

Python: Update Postgres Connector to new Design #7000

Closed

Description

Discussed in #6988

Originally posted by jamesmkfoo23 June 27, 2024
Hi, is postgres supported with Python?

Azure docs for Azure PostgreSQL Flexible python shows the usage psycopg2
https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/connect-python?tabs=cmd%2Cpasswordless#create-a-table-and-insert-data . I believe therefore this should be the correct library psycopg2.

Trying to use the connector but i'm getting this error when i try to import the postgres memory store

from semantic_kernel.connectors.memory.postgres import PostgresMemoryStore

semantic_kernel\connectors\memory\postgres\__init__.py:3
  from semantic_kernel.connectors.memory.postgres.postgres_memory_store import (PostgresMemoryStore)

semantic_kernel\connectors\memory\postgres\postgres_memory_store.py:9
  from psycopg import Cursor
  
ModuleNotFoundError: No module named 'psycopg'

Is there any samples for SK pg memory connector?

Activity

  1. changed the title [-]SK memory connector to postgres[/-] [+]Python: SK memory connector to postgres[/+] on Jun 28, 2024
  2. MaheshBudarapu commented on Jun 28, 2024

    @MaheshBudarapu

    Install Dependencies:
    Make sure you have the required dependencies installed:
    pip install psycopg
    pip install semantic-kernel

    from semantic_kernel import Kernel
    from semantic_kernel.connectors.memory.postgres import PostgresMemoryStore
    import psycopg2

    Database connection parameters

    db_params = {
    'dbname': 'your_database_name',
    'user': 'your_username',
    'password': 'your_password',
    'host': 'your_host',
    'port': 'your_port'
    }

    Create a connection to the database

    connection = psycopg2.connect(**db_params)

    Initialize the PostgresMemoryStore

    memory_store = PostgresMemoryStore(connection)

    Initialize the Kernel with the memory store

    kernel = Kernel(memory_store=memory_store)

    Example: Using the memory store

    Store some data

    memory_store.store('some_key', 'some_value')

    Retrieve stored data

    value = memory_store.retrieve('some_key')
    print(f'Retrieved value: {value}')

    Close the connection when done

    connection.close()

    Explanation:
    Install Dependencies: Ensure you have the psycopg and semantic-kernel packages installed.
    Database Connection Parameters: Update the db_params dictionary with your PostgreSQL database credentials.
    Create Connection: Establish a connection to the PostgreSQL database using psycopg2.connect.
    Initialize PostgresMemoryStore: Create an instance of PostgresMemoryStore using the database connection.
    Initialize Kernel: Pass the memory store to the Kernel initializer.
    Example Usage: Demonstrates storing and retrieving data from the memory store.
    Close Connection: Ensure the database connection is closed after operations are completed.

  3. changed the title [-]Python: SK memory connector to postgres[/-] [+]Python: Update Postgres[/+] on Aug 6, 2024
  4. changed the title [-]Python: Update Postgres[/-] [+]Python: Update Postgres Connector to new Design[/+] on Aug 6, 2024
  5. added
    sk team issueA tag to denote issues that where created by the Semantic Kernel team (i.e., not the community)
    on Aug 28, 2024
  6. Niladri24dutta commented on Sep 12, 2024

    @Niladri24dutta
    Contributor

    EvanChaki (@evchaki) is anyone working on this bug?

  7. evchaki commented on Sep 12, 2024

    @evchaki
    Contributor

    Eduard van Valkenburg (@eavanvalkenburg) - is this one you are working on with the new memory package?

  8. eavanvalkenburg commented on Sep 16, 2024

    @eavanvalkenburg
    Member

    Niladri Dutta (@Niladri24dutta) Mahesh Budarapu (@MaheshBudarapu) all memory connectors including this one will move over to the new memory connector model, over the next few weeks, if you want to contribute that would be great! The Azure AI Search, Redis and Qdrant connectors already have a new version (it is based on VectorStore and VectorStoreRecordCollection), we are finalizing the search side of things (CRUD is in those base classes), so once that is finalized then we can push to port the others, but you could give a start to that effort! We'll also keep this issue open to make sure we check the postgres package used.

  9. moved this from Backlog: Planned to Sprint: Done in Semantic Kernelon Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    IgniteFeatures planned for next Ignite conferencebugSomething isn't workingpythonPull requests for the Python Semantic Kernelsk team issueA tag to denote issues that where created by the Semantic Kernel team (i.e., not the community)

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions