Skip to content
Merged

Dev #127

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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.1.14"
version = "0.1.15"
description = "Knowing by reasoning, not vectors."
edition = "2024"
authors = ["zTgx <beautifularea@gmail.com>"]
Expand Down Expand Up @@ -97,7 +97,7 @@ rand = "0.8"
bm25 = { version = "2.3.2", features = ["parallelism"] }

# Python bindings
pyo3 = { version = "0.28", features = ["extension-module"] }
pyo3 = { version = "0.28", features = ["extension-module", "abi3-py311"] }
pyo3-async-runtimes = { version = "0.28", features = ["tokio-runtime"] }

# Dev dependencies
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# HISTORY

## 0.1.15 (2026-04-29)

- **Python bindings**: enabled PyO3 abi3 for cross-version compatibility
- Single wheel now supports Python 3.11, 3.12, and 3.13+
- Simplified exception type using `create_exception!` macro

## 0.1.14 (2026-04-29)

- Homepage redesign with product showcase and improved UX
Expand Down
17 changes: 8 additions & 9 deletions crates/vectorless-py/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::sync::Arc;

use pyo3::prelude::*;
use pyo3::exceptions::PyRuntimeError;
use pyo3_async_runtimes::tokio::future_into_py;
use tokio::sync::Mutex;

Expand All @@ -15,8 +16,6 @@ use vectorless_primitives::{
SectionCardInfo, SectionSummaryInfo, SimilarResult, TocEntry, TopicEntryInfo, WordCount,
};

use super::error::VectorlessError;

// =========================================================================
// PyDocumentInfo (existing — returned by compile)
// =========================================================================
Expand Down Expand Up @@ -126,7 +125,7 @@ fn id_to_str(id: u64) -> String {
}

fn to_py_err(e: impl std::fmt::Display) -> PyErr {
PyErr::from(VectorlessError::new(e.to_string(), "navigation"))
PyRuntimeError::new_err(e.to_string())
}

#[pymethods]
Expand Down Expand Up @@ -382,10 +381,10 @@ impl PyDocument {
let num = node_id
.strip_prefix('n')
.ok_or_else(|| {
VectorlessError::new("NodeId must start with 'n'".to_string(), "navigation")
PyRuntimeError::new_err("NodeId must start with 'n'")
})?
.parse::<u64>()
.map_err(|_| VectorlessError::new("Invalid NodeId".to_string(), "navigation"))?;
.map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?;
let nav = nav.lock().await;
Ok(nav
.chains_for(num)
Expand All @@ -403,10 +402,10 @@ impl PyDocument {
let num = node_id
.strip_prefix('n')
.ok_or_else(|| {
VectorlessError::new("NodeId must start with 'n'".to_string(), "navigation")
PyRuntimeError::new_err("NodeId must start with 'n'")
})?
.parse::<u64>()
.map_err(|_| VectorlessError::new("Invalid NodeId".to_string(), "navigation"))?;
.map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?;
let nav = nav.lock().await;
Ok(nav
.overlaps_for(num)
Expand All @@ -424,10 +423,10 @@ impl PyDocument {
let num = node_id
.strip_prefix('n')
.ok_or_else(|| {
VectorlessError::new("NodeId must start with 'n'".to_string(), "navigation")
PyRuntimeError::new_err("NodeId must start with 'n'")
})?
.parse::<u64>()
.map_err(|_| VectorlessError::new("Invalid NodeId".to_string(), "navigation"))?;
.map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?;
let nav = nav.lock().await;
Ok(nav.evidence_score_for(num).await.map(PyEvidenceScore::from))
})
Expand Down
17 changes: 4 additions & 13 deletions crates/vectorless-py/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
//! Engine Python wrapper — async compile/forget/list_documents.

use pyo3::prelude::*;
use pyo3::exceptions::PyRuntimeError;
use pyo3_async_runtimes::tokio::future_into_py;
use std::sync::Arc;
use tokio::runtime::Runtime;

use ::vectorless_engine::{Engine, EngineBuilder, IngestInput, RawNodeInput};

use super::document::{PyDocument, PyDocumentInfo};
use super::error::VectorlessError;
use super::error::to_py_err;
use super::graph::PyDocumentGraph;
use super::metrics::PyMetricsReport;
Expand Down Expand Up @@ -73,10 +73,7 @@ async fn run_load_document(engine: Arc<Engine>, doc_id: String) -> PyResult<PyDo
let navigator = vectorless_primitives::DocumentNavigator::new(d);
Ok(PyDocument::from_navigator(navigator))
}
None => Err(PyErr::from(VectorlessError::new(
format!("Document not found: {doc_id}"),
"navigation",
))),
None => Err(PyRuntimeError::new_err(format!("Document not found: {doc_id}"))),
}
}

Expand Down Expand Up @@ -144,10 +141,7 @@ impl PyEngine {
config: Option<PyRef<super::config::PyConfig>>,
) -> PyResult<Self> {
let rt = Runtime::new().map_err(|e| {
PyErr::from(VectorlessError::new(
format!("Failed to create tokio runtime: {}", e),
"config",
))
PyRuntimeError::new_err(format!("Failed to create tokio runtime: {}", e))
})?;

let rust_config = config.map(|c| c.inner.clone());
Expand All @@ -173,10 +167,7 @@ impl PyEngine {
});

let engine = engine.map_err(|e| {
PyErr::from(VectorlessError::new(
format!("Failed to create engine: {}", e),
"config",
))
PyRuntimeError::new_err(format!("Failed to create engine: {}", e))
})?;

Ok(Self {
Expand Down
61 changes: 2 additions & 59 deletions crates/vectorless-py/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,12 @@

//! Python exception types and error conversion.

use pyo3::exceptions::PyException;
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;

use ::vectorless_engine::Error as RustError;

/// Python exception for vectorless errors.
#[pyclass(extends = PyException, subclass, skip_from_py_object)]
pub struct VectorlessError {
message: String,
kind: String,
}

#[pymethods]
impl VectorlessError {
#[new]
fn new_py(message: String, kind: String) -> Self {
Self { message, kind }
}

#[getter]
fn message(&self) -> &str {
&self.message
}

#[getter]
fn kind(&self) -> &str {
&self.kind
}

fn __str__(&self) -> &str {
&self.message
}

fn __repr__(&self) -> String {
format!("VectorlessError('{}', kind='{}')", self.message, self.kind)
}
}

impl VectorlessError {
pub fn new(message: String, kind: &str) -> Self {
Self {
message,
kind: kind.to_string(),
}
}
}

impl From<VectorlessError> for PyErr {
fn from(err: VectorlessError) -> PyErr {
PyErr::new::<VectorlessError, _>((err.message, err.kind))
}
}

/// Convert vectorless errors to Python exceptions.
pub fn to_py_err(e: RustError) -> PyErr {
let message = e.to_string();
let kind = match &e {
RustError::DocumentNotFound(_) => "not_found",
RustError::Parse(_) => "parse",
RustError::Config(_) => "config",
RustError::Workspace(_) => "workspace",
RustError::Llm(_) => "llm",
_ => "unknown",
};
VectorlessError::new(message, kind).into()
PyRuntimeError::new_err(e.to_string())
}
3 changes: 1 addition & 2 deletions crates/vectorless-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use document::{
PyTocEntry, PyTopicEntry, PyWordCount,
};
use engine::PyEngine;
use error::VectorlessError;
use graph::{PyDocumentGraph, PyDocumentGraphNode, PyEdgeEvidence, PyGraphEdge, PyWeightedKeyword};
use metrics::{PyLlmMetricsReport, PyMetricsReport, PyRetrievalMetricsReport};

Expand All @@ -39,7 +38,7 @@ fn _vectorless(m: &Bound<'_, PyModule>) -> PyResult<()> {
.init();
});

m.add_class::<VectorlessError>()?;
// VectorlessError is just PyRuntimeError, no need to register
m.add_class::<PyEngine>()?;
m.add_class::<PyDocument>()?;
m.add_class::<PyDocumentInfo>()?;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Repository = "https://github.com/vectorlessflow/vectorless"
python-source = "."
module-name = "vectorless._vectorless"
manifest-path = "crates/vectorless-py/Cargo.toml"
features = ["pyo3/extension-module"]
features = ["pyo3/extension-module", "pyo3/abi3-py311"]

[tool.pytest.ini_options]
asyncio_mode = "auto"
Expand Down
Loading