Skip to main content

Simple, fast RAG library for Python

Project description

Cofone

Simple, fast, yours. Turn documents, websites and videos into a queryable knowledge base in a few lines of Python.

from cofone import RAG

answer = RAG().add_source("docs/").run("Who is Leonardo?")
print(answer)

What is Cofone?

Cofone is an open-source Python RAG (Retrieval-Augmented Generation) library. Load any document, ask questions in natural language, get precise answers — without complex setup or boilerplate.

Key highlights:

  • Fluent DSL — chain everything in one expression
  • BM25 + FAISS semantic search
  • 4 LLM providers: OpenRouter, OpenAI, Gemini, Ollama
  • Smart chunking that respects document structure
  • Chat memory, streaming, structured output (Pydantic)
  • Sources: files, folders, PDFs, web URLs, Wikipedia, YouTube

Quick start

# 1. clone and install
git clone https://github.com/yourname/cofone
cd cofone
pip install -e ".[all]"

# 2. create .env in project root
echo "OPENROUTER_API_KEY=sk-or-..." > .env

# 3. run
python -c "
from cofone import RAG
print(RAG().add_source('test/note_ex.txt').run('Summarize'))
"

For full installation instructions → see INSTALL.md
For all features with examples → see FEATURES.md


Minimal examples

from cofone import RAG

# file
RAG().add_source("notes.txt").run("Summarize")

# folder
RAG().add_source("docs/").run("What is the main topic?")

# web
RAG().add_source("https://en.wikipedia.org/wiki/Python").run("What is Python?")

# YouTube
RAG().add_source("https://www.youtube.com/watch?v=VIDEO_ID").run("What is this about?")

# FAISS semantic search
RAG(faiss=True).add_source("docs/").run("Find concepts related to learning")

# chat memory
bot = RAG().add_source("docs/")
bot.chat("Who is Leonardo?")
bot.chat("When was he born?")  # knows the context

# streaming
for token in RAG().add_source("docs/").stream("Tell me a story"):
    print(token, end="", flush=True)

# structured output
from pydantic import BaseModel
class Person(BaseModel):
    name: str
    birth_year: int
RAG().add_source("docs/").run("Extract data", schema=Person)

Providers

Provider Default model Key
OpenRouter arcee-ai/trinity-large-preview:free OPENROUTER_API_KEY
OpenAI gpt-4o-mini OPENAI_API_KEY
Gemini gemini-2.0-flash GEMINI_API_KEY
Ollama llama3 none (local)

Provider is auto-detected from model name — gpt-* → openai, gemini-* → gemini.


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cofone-0.1.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cofone-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file cofone-0.1.0.tar.gz.

File metadata

  • Download URL: cofone-0.1.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cofone-0.1.0.tar.gz
Algorithm Hash digest
SHA256 427b163fc4c0481d2c64db11ce2115bccfb6642557d9658c7edd5ff137314ca5
MD5 1b73c21b0194e32c4c5971238f961290
BLAKE2b-256 911ee214a90a4a8fa568f6be756b1cc4e3fb177d20134fc371ab0e762a6e5fd6

See more details on using hashes here.

File details

Details for the file cofone-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cofone-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cofone-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7dd11538ff55040c1aa51eaa18a2e1e8701d2bdc5075e04ad51a92e587eb8a7e
MD5 2249da410c8e5513aff781b6878f22f8
BLAKE2b-256 100a7322223333432d1bffb358de54a8bf518fb65b0b766b5c51a6e72afee26a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page