π¦ What is Korvus?
Korvus is an innovative, open-source software development kit (SDK) designed to streamline the process of Retrieval-Augmented Generation (RAG) using PostgreSQL. It seamlessly integrates various components such as Large Language Models (LLMs), vector memory, embedding generation, ranking, summarization, and custom models into a single, efficient query, offering high performance and a simple search architecture.
π Languages
Korvus supports multiple programming languages, making it adaptable to different development environments:
- Python: Available as a package on PyPI.
- JavaScript: Offered through npm.
- Rust: Obtainable from Crates.io.
- C: Can be built from source as detailed in its documentation.
π Why Korvus?
Korvus leverages PostgreSQL's robust database capabilities to execute RAG operations, eliminating the need for external services and ensuring reduced latency and complexity:
- Postgres-Native RAG: Operates RAG processes directly in the database, minimizing external dependencies.
- Single Query Efficiency: Executes entire RAG pipelines in one SQL query, simplifying workflows and enhancing speed.
- Scalability and Performance: Built on PostgreSQL's scalable architecture, it maintains excellent performance even as data scales.
β‘ Key Features
- Simplified Architecture: Allows users to replace complex setups with a single robust SQL query.
- High Performance: Reduces the need for API calls, optimizing processing speed and reliability.
- Open Source: Enhances developer freedom with open-source software, compatible with local Docker environments.
- Multi-Language Support: Compatible with leading programming languages, with potential support for more upon request.
- Unified Pipeline: Facilitates embedding generation, vector search, reranking, and text generation in one combined process.
- Postgres-Powered: Utilizes efficient SQL operations on PostgreSQL's platform for enhanced functionality.
𧩠System Architecture
Korvus utilizes the PostgresML's pgml
extension along with the pgvector
extension. This combination allows the RAG pipeline to be efficiently compressed within PostgreSQL, optimizing both performance and simplicity.
π Get Started
π Prerequisites
Before using Korvus, ensure you have a PostgreSQL database with pgml
and pgvector
installed. You can opt for self-hosting or using a managed service.
-
Self-hosted: Set up your own database. Follow the self-hosting guide.
-
Hosted Service: Use the managed service with pre-installed extensions. Sign up here.
π Quick Start
-
Install Korvus with Python:
pip install korvus
-
Set your database URL:
export KORVUS_DATABASE_URL="{YOUR DATABASE CONNECTION STRING}"
-
Create 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())
-
Insert documents into the collection:
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())
-
Execute RAG operations:
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
Korvus's underlying operations are based on SQL, which offers transparency, customization, and optimal performance while abstracting complexity through its intuitive APIs.
π Documentation
For complete details, refer to the official documentation.
π Community
Engage with the community for support, idea-sharing, and contributions:
π€ Contributing
Korvus welcomes contributions. For guidelines on contributing, review the Contribution Guidelines.
Korvus is proudly maintained by PostgresML. For advanced support and consulting, feel free to reach out.