As AI-driven applications continue to evolve, the need for efficient vector-based search capabilities is greater than ever. Microsoft Semantic Kernel makes it easy to integrate these capabilities with PostgreSQL databases using the Postgres connector. Whether you're leveraging cloud-hosted PostgreSQL instances on Amazon Web Services or Google Cloud, this connector enables seamless interaction, allowing you to store and query vectorized data for tasks like recommendation systems, semantic search, and more.Compatible DatabasesSemantic Kernel Postgres Connector is compatible with PostgreSQL instances hosted locally or in cloud including but not limited to: Amazon RDS for PostgreSQL Google AlloyDB for PostgreSQL Google Cloud SQL for PostgreSQLSetup InstructionsEnable pgvector extensionOnce your database is configured on AWS or GCP, enable vector similarity search by installing the pgvector extension:CREATE EXTENSION IF NOT EXISTS vector;Install the Semantic Kernel PostgreSQL Connector.NETdotnet add package Microsoft.SemanticKernel.Connectors.Postgres --prereleasePythonpip install semantic-kernel[postgres]Define Your Data Model.NETusing Microsoft.Extensions.VectorData;public class Hotel{ [VectorStoreRecordKey] public ulong HotelId { get; set; } [VectorStoreRecordData(IsFilterable = true)] public string HotelName { get; set; } [VectorStoreRecordData(IsFullTextSearchable = true)] public string Description { get; set; } [VectorStoreRecordVector(4, DistanceFunction.CosineDistance, IndexKind.Hnsw)] public ReadOnlyMemory? DescriptionEmbedding { get; set; } [VectorStoreRecordData(IsFilterable = true)] public string[] Tags { get; set; }}Pythonfrom uuid import uuid4from dataclasses import dataclass, fieldfrom typing import Annotatedfrom semantic_kernel.data import ( DistanceFunction, IndexKind, VectorStoreRecordDataField, VectorStoreRecordKeyField, VectorStoreRecordVectorField, vectorstoremodel)@vectorstoremodel@dataclassclass Hotel: hotel_id: Annotated[str, VectorStoreRecordKeyField()] = field(default_factory=lambda: str(uuid4())) hotel_name: Annotated[str, VectorStoreRecordDataField(is_filterable=True)] description: Annotated[str, VectorStoreRecordDataField(is_full_text_searchable=True)] description_embedding: Annotated[list[float], VectorStoreRecordVectorField(dimensions=4, distance_function=DistanceFunction.COSINE, index_kind=IndexKind.HNSW)] tags: Annotated[list[str], VectorStoreRecordDataField(is_filterable=True)]Configure the Vector Store.NETusing Microsoft.SemanticKernel.Connectors.Postgres;using Npgsql;NpgsqlDataSourceBuilder dataSourceBuilder = new("Host=;Port=5432;Username=;Password=;Database=;");dataSourceBuilder.UseVector();var dataSource = dataSourceBuilder.Build();var vectorStore = new PostgresVectorStore(dataSource);Pythonfrom semantic_kernel.connectors.memory.postgres import PostgresSettings, PostgresStorefrom collections.abc import AsyncGeneratorfrom pydantic import SecretStrsettings = PostgresSettings( host="", port=5432, user="", password=SecretStr(""), dbname="")async def get_vector_store() -> AsyncGenerator[PostgresStore, None]: async with await settings.create_connection_pool() as pool: yield PostgresStore(connection_pool=pool)Perform a Vector Search.NET// Placeholder embedding generation method.async Task GenerateEmbeddingAsync(string textToVectorize){ // your logic here}IVectorStoreRecordCollection collection = vectorStore.GetCollection("hotels");// Generate a vector for your search text.ReadOnlyMemory searchVector = await GenerateEmbeddingAsync("I'm looking for a hotel where customer happiness is the priority.");// Perform the search.var searchResult = await collection.VectorizedSearchAsync(searchVector, new() { Top = 1 });// Display results.await foreach (var record in searchResult.Results){ Console.WriteLine("Found hotel description: " + record.Record.Description);}Pythonfrom semantic_kernel.data.vector_search import VectorSearchOptionsasync def vector_search(): store = await get_vector_store() collection = store.get_collection("hotels", Hotel) # Generate a vector for your search text. vector = await generate_vector("I'm looking for a hotel where customer happiness is the priority.") search_results = await collection.vectorized_search( vector=vector, options=VectorSearchOptions(vector_field_name="vector") ) hotels = [record.record async for record in search_results.results] print(f"Found hotels: {hotels}")More information What are Semantic Kernel Vector Store connectors? Defining your data model Vector search using Semantic Kernel Vector Store connectors Using the Postgres Vector Store connectorSummaryThis example demonstrates how to leverage Microsoft Semantic Kernel with PostgreSQL databases on AWS and GCP to perform efficient vector searches. By setting up the pgvector extension and integrating the Semantic Kernel connector, you can store and retrieve vectorized data with ease. Whether you're building recommendation systems, semantic search applications, or AI-powered insights, this approach ensures scalable and effective vector storage and retrieval.We’re always interested in hearing from you. If you have feedback, questions or want to discuss further, feel free to reach out to us and the community on the discussion boards on GitHub! We would also love your support, if you've enjoyed using Semantic Kernel, give us a star on GitHub.