postgresml / korvus

Korvus is a search SDK that unifies the entire RAG pipeline in a single database query. Built on top of Postgres with bindings for Python, JavaScript, Rust and C.
https://postgresml.org
MIT License
1.27k stars 24 forks source link
ai embeddings javascript llm ml python rag search sql
Logo

One query to rule them all

| Documentation | Blog | Discord |


Korvus is a search SDK that unifies the entire RAG pipeline in a single database query. Built on top of Postgres with bindings for Python, JavaScript and Rust, Korvus delivers high-performance, customizable search capabilities with minimal infrastructure concerns.

📕 Table of Contents - [🦅 What is Korvus?](#-what-is-korvus) - [🔠 Languages](#-languages) - [🏆 Why Korvus?](#-why-korvus) - [⚡ Key Features](#-key-features) - [🧩 System Architecture](#-system-architecture) - [🚀 Get Started](#-get-started) - [🔍 The Power of SQL](#-the-power-of-sql) - [📘 Documentation](#-documentation) - [🌐 Community](#-community) - [🤝 Contributing](#-contributing)

https://github.com/postgresml/korvus/assets/19626586/2b697dc6-8c38-41a7-8c8e-ef158dacb29b

🦅 What is Korvus?

Korvus is an all-in-one, open-source RAG (Retrieval-Augmented Generation) pipeline built for Postgres. It combines LLMs, vector memory, embedding generation, reranking, summarization and custom models into a single query, maximizing performance and simplifying your search architecture.

korvus-demo

🔠 Languages

Korvus provides SDK support for multiple programming languages, allowing you to integrate it seamlessly into your existing tech stack:

🏆 Why Korvus?

Korvus stands out by harnessing the full power of Postgres for RAG operations:

  1. Postgres-Native RAG: Korvus leverages Postgres' robust capabilities, allowing you to perform complex RAG operations directly within your database. This approach eliminates the need for external services and API calls, significantly reducing latency and complexity many times over.

  2. Single Query Efficiency: With Korvus, your entire RAG pipeline - from embedding generation to text generation - is executed in a single SQL query. This "one query to rule them all" approach simplifies your architecture and boosts performance.

  3. Scalability and Performance: By building on Postgres, Korvus inherits its excellent scalability and performance characteristics. As your data grows, Korvus grows with it, maintaining high performance even with large datasets.

⚡ Key Features

🧩 System Architecture

Korvus utilizes PostgresML's pgml extension and the pgvector extension to compress the entire RAG pipeline inside of Postgres.

PostgresML_Old-V-New_Diagram-Update

🚀 Get Started

📋 Prerequisites

To use Korvus, you need a Postgres database with pgml and pgvector installed. You have two options:

  1. Self-hosted: Set up your own database with pgml and pgvector.

  2. Hosted Service: Use our managed Postgres service with pgml and pgvector pre-installed.

🏁 Quick Start

  1. Install Korvus:
pip install korvus
  1. Set the KORVUS_DATABASE_URL env variable:
export KORVUS_DATABASE_URL="{YOUR DATABASE CONNECTION STRING}"
  1. Initialize a Collection and Pipeline:
from korvus import Collection, Pipeline
import asyncio

collection = Collection("korvus-demo-v0")
pipeline = Pipeline(
    "v1",
    {
        "text": {
            "splitter": {"model": "recursive_character"},
            "semantic_search": {"model": "Alibaba-NLP/gte-base-en-v1.5"},
        }
    },
)

async def add_pipeline():
    await collection.add_pipeline(pipeline)

asyncio.run(add_pipeline())
  1. Insert documents:
    
    async def upsert_documents():
    documents = [
        {"id": "1", "text": "Korvus is incredibly fast and easy to use."},
        {"id": "2", "text": "Tomatoes are incredible on burgers."},
    ]
    await collection.upsert_documents(documents)

asyncio.run(upsert_documents())


5. Perform RAG
```python
async def rag():
    query = "Is Korvus fast?"
    print(f"Querying for response to: {query}")
    results = await collection.rag(
        {
            "CONTEXT": {
                "vector_search": {
                    "query": {
                        "fields": {"text": {"query": query}},
                    },
                    "document": {"keys": ["id"]},
                    "limit": 1,
                },
                "aggregate": {"join": "\n"},
            },
            "chat": {
                "model": "meta-llama/Meta-Llama-3-8B-Instruct",
                "messages": [
                    {
                        "role": "system",
                        "content": "You are a friendly and helpful chatbot",
                    },
                    {
                        "role": "user",
                        "content": f"Given the context\n:{{CONTEXT}}\nAnswer the question: {query}",
                    },
                ],
                "max_tokens": 100,
            },
        },
        pipeline,
    )
    print(results)

asyncio.run(rag())

🔍 The Power of SQL

While Korvus provides a high-level interface in multiple programming languages, its core operations are built on optimized SQL queries. This approach offers several advantages:

Don't worry if you're not a SQL expert - Korvus's intuitive API abstracts away the complexity while still allowing you to harness the full power of SQL-based operations.

📘 Documentation

For comprehensive documentation, including API references, tutorials, and best practices, visit our official documentation.

🌐 Community

Join our community to get help, share ideas, and contribute:

🤝 Contributing

We welcome contributions to Korvus! Please read our Contribution Guidelines before submitting pull requests.


Korvus is maintained by PostgresML. For enterprise support and consulting services, please contact us.