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
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ exclude = [
anyhow = "1"
async-trait = "0.1"
chrono = { version = "0.4", features = ["serde"] }
git2 = "0.19"
# Native-linking deps pinned to OpenHuman's versions so the host and the crate
# link ONE bundled SQLite and ONE libgit2 (both are `links = "…"` crates; two
# versions in one binary is a hard Cargo error). Keep in lockstep with the host
# root Cargo.toml when either side bumps.
git2 = { version = "0.21", default-features = false, features = ["vendored-libgit2"] }
parking_lot = "0.12"
rand = "0.8"
regex = "1"
rusqlite = { version = "0.32", features = ["bundled"] }
rusqlite = { version = "0.40", features = ["bundled"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.10"
Expand Down
15 changes: 10 additions & 5 deletions src/memory/diff/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ impl Ledger {
};
Ok(Some(checkpoint_from_message(
checkpoint_id,
tag.message().unwrap_or(""),
// git2 0.21: Tag::message() is Result<Option<&str>, _>; a non-UTF8
// or missing message degrades to an empty checkpoint body.
tag.message().ok().flatten().unwrap_or(""),
)))
}

Expand All @@ -375,8 +377,9 @@ impl Ledger {
let pattern = format!("{CHECKPOINT_PREFIX}*");
let names = self.repo.tag_names(Some(&pattern))?;
let mut out = Vec::new();
// StringArray::iter() yields Option<&str>; drop non-utf8 names.
for name in names.iter().flatten() {
// git2 0.21: StringArray::iter() yields Result<Option<&str>, _>; keep
// only successfully-decoded utf8 names.
for name in names.iter().filter_map(|r| r.ok().flatten()) {
if let Some(ckpt) = self.get_checkpoint(name)? {
out.push(ckpt);
}
Expand All @@ -394,7 +397,8 @@ impl Ledger {
let pattern = format!("{CHECKPOINT_PREFIX}*");
let names = self.repo.tag_names(Some(&pattern))?;
let mut deleted = 0u64;
for name in names.iter().flatten() {
// git2 0.21: StringArray::iter() yields Result<Option<&str>, _>.
for name in names.iter().filter_map(|r| r.ok().flatten()) {
if let Some(ckpt) = self.get_checkpoint(name)? {
if ckpt.created_at_ms < older_than_ms {
self.repo.tag_delete(name)?;
Expand Down Expand Up @@ -545,7 +549,8 @@ fn oid_hash(oid: Oid) -> Option<String> {
fn patch_text(diff: &git2::Diff, delta_idx: usize) -> Option<String> {
let mut patch = git2::Patch::from_diff(diff, delta_idx).ok().flatten()?;
let buf = patch.to_buf().ok()?;
let text = buf.as_str()?;
// git2 0.21: Buf::as_str() returns Result<&str, Utf8Error>.
let text = buf.as_str().ok()?;
if text.trim().is_empty() {
None
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/memory/store/vectors/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use std::path::Path;
use std::sync::Arc;

use anyhow::Context;
use parking_lot::Mutex;
use rusqlite::Connection;

Expand Down Expand Up @@ -369,15 +370,18 @@ impl VectorStore {
/// Returns the number of entries in a namespace (or all if `None`).
pub fn count(&self, namespace: Option<&str>) -> anyhow::Result<usize> {
let conn = self.conn.lock();
let count: usize = match namespace {
// SQLite COUNT(*) is an i64; rusqlite (>= 0.33) no longer implements
// FromSql for usize, so read as i64 and convert. Overflow is impossible
// in practice but handled rather than silently truncated.
let count: i64 = match namespace {
Some(ns) => conn.query_row(
"SELECT COUNT(*) FROM vectors WHERE namespace = ?1",
rusqlite::params![ns],
|row| row.get(0),
)?,
None => conn.query_row("SELECT COUNT(*) FROM vectors", [], |row| row.get(0))?,
};
Ok(count)
usize::try_from(count).context("vector count did not fit in usize")
}

/// Lists all distinct namespaces.
Expand Down
Loading