Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,29 @@ jobs:
uv run ruff format --check src tests
- name: Test
run: uv run pytest --cov --cov-report=term --cov-fail-under=80

desktop:
runs-on: windows-latest
defaults:
run:
working-directory: desktop
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: desktop/web/package-lock.json
- name: Interface
working-directory: desktop/web
run: |
npm ci
npx tsc -b
npx eslint .
npx vitest run
npm run build
- name: App and tests
run: dotnet test OpenRag.slnx -c Release
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
/lib/
/lib64/
parts/
sdist/
var/
Expand Down Expand Up @@ -221,3 +221,9 @@ __marimo__/

# open-rag-engine local data
.ore/

# Desktop app build output
desktop/**/bin/
desktop/**/obj/
desktop/web/node_modules/
desktop/web/dist/
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ We just finished a full course on retrieval-augmented generation and built a sma

## Try it

You need Python 3.12+, [uv](https://docs.astral.sh/uv/) and [Ollama](https://ollama.com/).
**On Windows, without installing anything else:** download Open RAG, the desktop app, from the
[latest release](https://github.com/Carthavate/open-rag-engine/releases/latest). Put the `.exe` and its `.bin` parts in
one folder and run the `.exe`. It brings its own models and works offline.

**From source:** you need Python 3.12+, [uv](https://docs.astral.sh/uv/) and [Ollama](https://ollama.com/).

```bash
uv sync
Expand Down Expand Up @@ -88,5 +92,7 @@ We review each other's work through pull requests. See [CONTRIBUTING.md](CONTRIB

## Team

- [Wadi](https://github.com/TWadi)
- [Ghassen](https://github.com/GhassenJamoussi99)
Open RAG is developed by:

- Wadi Touil: [GitHub](https://github.com/TWadi) · [LinkedIn](https://www.linkedin.com/in/wadi-touil-117472319/)
- Ghassen Jamoussi: [GitHub](https://github.com/GhassenJamoussi99) · [LinkedIn](https://www.linkedin.com/in/ghassen-jamoussi/)
9 changes: 9 additions & 0 deletions desktop/OpenRag.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Solution>
<Folder Name="/src/">
<Project Path="src/OpenRag.App/OpenRag.App.csproj" />
<Project Path="src/OpenRag.Core/OpenRag.Core.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/OpenRag.Core.Tests/OpenRag.Core.Tests.csproj" />
</Folder>
</Solution>
60 changes: 60 additions & 0 deletions desktop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Open RAG (desktop app)

A Windows app for teachers, researchers and students. Organise documents into **categories** (a subject or research
area) and **sections** (a course, session, project or reading list). Ask questions and get cited answers from one section, or
from a whole category. Everything runs on this computer: see [ADR-0007](../docs/adr/0007-desktop-app.md).

It looks like the [AI Engineering Arena](https://carthavate.github.io/ai-engineering-arena): the same "sticker arcade" theme,
in light or dark to match Windows, with the fonts bundled so it looks the same offline.

## How it fits together

```text
OpenRag.exe (WPF)
├─ WebView2 ── the React interface (web/), served from the app's folder as https://app.ore
│ │ messages: api, ask, cancel, pickFolder, openSource, …
│ ▼
├─ EngineProxy ── adds the per-launch token, allows only the engine's API paths
│ │ HTTP on 127.0.0.1
│ ▼
└─ engine ─────── `ore serve` (Python), started and stopped by the app (job object + --parent-pid)
```

The page never sees the token and never talks to a local port. Answers stream back line by line through the window.

| Folder | What |
|---|---|
| `src/OpenRag.App` | WPF shell: window, WebView2, folder dialog, opening cited files, engine lifetime |
| `src/OpenRag.Core` | Finding and starting the engine, the API proxy, safe file opening (unit-tested) |
| `web/` | React 19 + Tailwind 4 interface, with a mock engine for working in a browser |
| `tools/make_icon.py` | Draws the app icon |

## Develop

You need the .NET 10 SDK, Node 20 and, for the engine, `uv` with the repo's Python setup (see the main README).

```bash
cd desktop
dotnet build OpenRag.slnx # builds web/ the first time, then the app
dotnet test OpenRag.slnx
```

Run `src/OpenRag.App/bin/Debug/net10.0-windows/OpenRag.exe`. In a checkout it finds the engine by walking up to
`pyproject.toml` and starts it with `uv run ore serve`. `OPENRAG_ENGINE_DIR` points it at another checkout. Its data lives
in `%LOCALAPPDATA%\OpenRag` and the engine's log is in `%LOCALAPPDATA%\OpenRag\logs\engine.log`.

To work on the interface:

```bash
cd desktop/web
npm run dev # http://localhost:5176 with a mock engine, no Python needed
npm test
```

- **Against a real engine in the browser:** start `ORE_API_TOKEN=<32+ chars> uv run ore serve --origin http://localhost:5176`, then open `http://localhost:5176/?api=http://127.0.0.1:<port>&token=<token>`.
- **Live reload inside the app (Debug builds only):** set `OPENRAG_DEV_URL=http://localhost:5176` before starting `OpenRag.exe`.

## Installer

`installer/build.py` builds `OpenRag-Setup.exe`, a self-contained setup that brings its own Python, models and
llama.cpp server, so it needs no internet after installing. See [installer/README.md](../installer/README.md).
3 changes: 3 additions & 0 deletions desktop/src/OpenRag.App/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Application x:Class="OpenRag.App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />
39 changes: 39 additions & 0 deletions desktop/src/OpenRag.App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.IO;
using System.Windows;
using System.Windows.Threading;
using OpenRag.Core;

namespace OpenRag.App;

public partial class App : Application
{
/// <summary>Opens the window, unless Open RAG is already running. Unexpected errors are written down and
/// the window kept alive, instead of closing without a trace.</summary>
protected override void OnStartup(StartupEventArgs e)
{
if (!SingleInstance.Claim())
{
Shutdown();
return;
}
DispatcherUnhandledException += OnUnhandled;
base.OnStartup(e);
new MainWindow().Show();
}

private static void OnUnhandled(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var log = AppPaths.Default.ErrorLog;
try
{
Directory.CreateDirectory(Path.GetDirectoryName(log)!);
File.AppendAllText(log, $"{DateTime.Now:u} {e.Exception}\n\n");
}
catch (Exception logError) when (logError is IOException or UnauthorizedAccessException)
{
// Nowhere to write it; the message box below still tells the user.
}
MessageBox.Show($"Something went wrong, but Open RAG kept running.\n\n{e.Exception.Message}\n\nDetails: {log}", "Open RAG");
e.Handled = true;
}
}
10 changes: 10 additions & 0 deletions desktop/src/OpenRag.App/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Binary file added desktop/src/OpenRag.App/Assets/OpenRag.ico
Binary file not shown.
Binary file added desktop/src/OpenRag.App/Assets/OpenRag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions desktop/src/OpenRag.App/ChildProcessJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace OpenRag.App;

/// <summary>A Windows job object that kills its processes when Open RAG exits, even after a crash, so the engine
/// never keeps running (and holding its indexes) without the app.</summary>
internal sealed class ChildProcessJob : IDisposable
{
private const int JobObjectExtendedLimitInformation = 9;
private const uint JobObjectLimitKillOnJobClose = 0x2000;

private readonly IntPtr _handle;

[StructLayout(LayoutKind.Sequential)]
private struct BasicLimitInformation
{
public long PerProcessUserTimeLimit;
public long PerJobUserTimeLimit;
public uint LimitFlags;
public UIntPtr MinimumWorkingSetSize;
public UIntPtr MaximumWorkingSetSize;
public uint ActiveProcessLimit;
public UIntPtr Affinity;
public uint PriorityClass;
public uint SchedulingClass;
}

[StructLayout(LayoutKind.Sequential)]
private struct IoCounters
{
public ulong ReadOperationCount, WriteOperationCount, OtherOperationCount, ReadTransferCount, WriteTransferCount, OtherTransferCount;
}

[StructLayout(LayoutKind.Sequential)]
private struct ExtendedLimitInformation
{
public BasicLimitInformation BasicLimitInformation;
public IoCounters IoInfo;
public UIntPtr ProcessMemoryLimit;
public UIntPtr JobMemoryLimit;
public UIntPtr PeakProcessMemoryUsed;
public UIntPtr PeakJobMemoryUsed;
}

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr CreateJobObject(IntPtr attributes, string? name);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetInformationJobObject(IntPtr job, int infoClass, ref ExtendedLimitInformation info, int length);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool CloseHandle(IntPtr handle);

public ChildProcessJob()
{
_handle = CreateJobObject(IntPtr.Zero, null);
if (_handle == IntPtr.Zero)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
var info = new ExtendedLimitInformation { BasicLimitInformation = new BasicLimitInformation { LimitFlags = JobObjectLimitKillOnJobClose } };
if (!SetInformationJobObject(_handle, JobObjectExtendedLimitInformation, ref info, Marshal.SizeOf<ExtendedLimitInformation>()))
{
var error = Marshal.GetLastWin32Error();
CloseHandle(_handle);
throw new Win32Exception(error);
}
}

/// <summary>Adds the process (and the children it starts later) to the job. A failure only loses the crash safety net.</summary>
public void Add(Process process)
{
try
{
if (!AssignProcessToJobObject(_handle, process.Handle))
{
Debug.WriteLine($"Couldn't add the engine to the job: error {Marshal.GetLastWin32Error()}");
}
}
catch (Exception e) when (e is InvalidOperationException or Win32Exception)
{
Debug.WriteLine($"Couldn't add the engine to the job: {e.Message}");
}
}

public void Dispose() => CloseHandle(_handle);
}
17 changes: 17 additions & 0 deletions desktop/src/OpenRag.App/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window x:Class="OpenRag.App.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
Title="Open RAG" Icon="Assets/OpenRag.ico" Width="1320" Height="820" MinWidth="980" MinHeight="620"
WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="CanResize" Background="#EAF2FF">
<!-- No Windows title bar: the page draws its own, in the Arena style, as a WebView2 drag region.
WindowChrome keeps resizing from the thin border around the page, and the window's shadow. -->
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome CaptionHeight="0" ResizeBorderThickness="5" GlassFrameThickness="0,0,0,1" UseAeroCaptionButtons="False" />
</shell:WindowChrome.WindowChrome>
<Border x:Name="Frame" Padding="4">
<!-- The whole interface is the React app in desktop/web; this window only hosts it and the engine. -->
<wv2:WebView2 x:Name="Web" />
</Border>
</Window>
Loading
Loading