Compare commits

..
3 Commits
Author SHA1 Message Date
Nicolò Boschi 7972fd3906 feat: support litellm-sdk for reranker endpoint 2026-02-12 14:43:35 +01:00
Nicolò Boschi 86b698460e chore: remove dead code 2026-02-12 14:21:53 +01:00
Nicolò Boschi 6f9cef674b chore: remove dead code 2026-02-12 14:21:26 +01:00
356 changed files with 1203 additions and 46869 deletions
-6
View File
@@ -41,12 +41,6 @@ HINDSIGHT_API_LOG_LEVEL=info
# HINDSIGHT_API_DATABASE_URL=postgresql://user:pass@host:5432/db
# HINDSIGHT_API_DATABASE_SCHEMA=public # PostgreSQL schema name (default: public)
# Vector Extension (Optional - uses pgvector by default)
# Options: "pgvector" (default), "vchord", "pgvectorscale" (DiskANN)
# HINDSIGHT_API_VECTOR_EXTENSION=pgvector
# For Azure PostgreSQL with DiskANN:
# HINDSIGHT_API_VECTOR_EXTENSION=pgvectorscale # Auto-detects pg_diskann on Azure
# Embeddings Configuration (Optional - uses local by default)
# Provider: "local" (default) or "tei" (HuggingFace Text Embeddings Inference)
# HINDSIGHT_API_EMBEDDINGS_PROVIDER=local
+21 -80
View File
@@ -648,84 +648,6 @@ jobs:
echo "=== API Server Logs ==="
cat /tmp/api-server.log || echo "No API server log found"
test-go-client:
runs-on: ubuntu-latest
env:
HINDSIGHT_API_LLM_PROVIDER: groq
HINDSIGHT_API_LLM_API_KEY: ${{ secrets.GROQ_API_KEY }}
HINDSIGHT_API_LLM_MODEL: openai/gpt-oss-20b
HINDSIGHT_API_URL: http://localhost:8888
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Prefer CPU-only PyTorch in CI (but keep PyPI for everything else)
UV_INDEX: pytorch=https://download.pytorch.org/whl/cpu
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
prune-cache: false
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache-dependency-path: hindsight-clients/go/go.sum
- name: Build API
working-directory: ./hindsight-api
run: uv build
- name: Install API dependencies
working-directory: ./hindsight-api
run: uv sync --frozen --no-install-project --index-strategy unsafe-best-match
- name: Create .env file
run: |
cat > .env << EOF
HINDSIGHT_API_LLM_PROVIDER=${{ env.HINDSIGHT_API_LLM_PROVIDER }}
HINDSIGHT_API_LLM_API_KEY=${{ env.HINDSIGHT_API_LLM_API_KEY }}
HINDSIGHT_API_LLM_MODEL=${{ env.HINDSIGHT_API_LLM_MODEL }}
EOF
- name: Start API server
run: |
./scripts/dev/start-api.sh > /tmp/api-server.log 2>&1 &
echo "Waiting for API server to be ready..."
for i in {1..60}; do
if curl -sf http://localhost:8888/health > /dev/null 2>&1; then
echo "API server is ready after ${i}s"
break
fi
if [ $i -eq 60 ]; then
echo "API server failed to start after 60s"
cat /tmp/api-server.log
exit 1
fi
sleep 1
done
- name: Build Go client
working-directory: ./hindsight-clients/go
run: go build ./...
- name: Run Go client tests
working-directory: ./hindsight-clients/go
run: go test -v -tags=integration
- name: Show API server logs
if: always()
run: |
echo "=== API Server Logs ==="
cat /tmp/api-server.log || echo "No API server log found"
test-integration:
runs-on: ubuntu-latest
env:
@@ -1019,11 +941,30 @@ jobs:
sleep 1
done
- name: Run Python doc examples
working-directory: ./hindsight-clients/python
run: |
for f in ../../hindsight-docs/examples/api/*.py; do
echo "Running $f..."
uv run python "$f"
done
- name: Run Node.js doc examples
run: |
for f in hindsight-docs/examples/api/*.mjs; do
echo "Running $f..."
node "$f"
done
- name: Configure CLI
run: hindsight configure --api-url http://localhost:8888
- name: Run all doc examples
run: ./scripts/test-doc-examples.sh
- name: Run CLI doc examples
run: |
for f in hindsight-docs/examples/api/*.sh; do
echo "Running $f..."
bash "$f"
done
- name: Show API server logs
if: always()
-1
View File
@@ -46,7 +46,6 @@ hindsight-docs/static/llms-full.txt
hindsight-dev/benchmarks/locomo/results/
hindsight-dev/benchmarks/longmemeval/results/
hindsight-dev/benchmarks/consolidation/results/
hindsight-dev/benchmarks/perf/results/
benchmarks/results/
hindsight-cli/target
hindsight-clients/rust/target
-7
View File
@@ -57,15 +57,8 @@ cd hindsight-control-plane && npm run dev
### Benchmarks
```bash
# Accuracy benchmarks
./scripts/benchmarks/run-longmemeval.sh
./scripts/benchmarks/run-locomo.sh
# Performance benchmarks
./scripts/benchmarks/run-consolidation.sh
./scripts/benchmarks/run-retain-perf.sh --document <path> # Requires API server running
# Results viewer
./scripts/benchmarks/start-visualizer.sh # View results at localhost:8001
```
@@ -1,32 +0,0 @@
# PostgreSQL with pgvector and pg_textsearch extensions
# Note: pg_textsearch requires PostgreSQL 17+
FROM postgres:17
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
postgresql-server-dev-17 \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Install pgvector
RUN cd /tmp && \
git clone --branch v0.8.0 https://github.com/pgvector/pgvector.git && \
cd pgvector && \
make && \
make install
# Install pg_textsearch
RUN cd /tmp && \
git clone https://github.com/timescale/pg_textsearch.git && \
cd pg_textsearch && \
make && \
make install
# Clean up source files and build dependencies
RUN rm -rf /tmp/pgvector /tmp/pg_textsearch && \
apt-get purge -y --auto-remove build-essential git postgresql-server-dev-17
# Ensure extensions are preloaded
RUN echo "shared_preload_libraries = 'pg_textsearch'" >> /usr/share/postgresql/postgresql.conf.sample
@@ -1,91 +0,0 @@
name: hindsight
# Docker Compose file for Hindsight with PostgreSQL and Timescale pg_textsearch
# docker compose -f docker/docker-compose/pg_textsearch/docker-compose.yaml down && sleep 2 && docker compose -f docker/docker-compose/pg_textsearch/docker-compose.yaml up -d
# Make sure to set the required environment variables before running:
# - HINDSIGHT_DB_PASSWORD: Password for the PostgreSQL user
# - Configure LLM provider variables as needed (see below in the hindsight service)
#
# Usage:
# docker compose up -d
#
# Optional environment variables with defaults:
# - HINDSIGHT_VERSION: Hindsight application version (default: latest)
# - HINDSIGHT_DB_USER: PostgreSQL user (default: hindsight_user)
# - HINDSIGHT_DB_NAME: PostgreSQL database name (default: hindsight_db)
services:
db:
# Use custom PostgreSQL image with pgvector and pg_textsearch extensions
build:
context: .
dockerfile: Dockerfile
container_name: hindsight-db
restart: always
# Expose PostgreSQL port
ports:
- "5437:5432"
environment:
POSTGRES_USER: ${HINDSIGHT_DB_USER:-hindsight_user}
POSTGRES_PASSWORD: ${HINDSIGHT_DB_PASSWORD:-hindsight_password}
POSTGRES_DB: ${HINDSIGHT_DB_NAME:-hindsight_db}
volumes:
- pg_data:/var/lib/postgresql/data
networks:
- hindsight-net
pg-textsearch-init:
build:
context: .
dockerfile: Dockerfile
depends_on:
- db
environment:
- PGPASSWORD=${HINDSIGHT_DB_PASSWORD:-hindsight_password}
command: >
bash -c "
echo 'Waiting for PostgreSQL to be ready...';
until pg_isready -h hindsight-db -p 5432 -U hindsight_user; do
echo 'PostgreSQL is unavailable - sleeping';
sleep 2;
done;
echo 'PostgreSQL is ready - creating hindsight_db database';
psql -h hindsight-db -p 5432 -U hindsight_user -c 'CREATE DATABASE hindsight_db;' 2>/dev/null || echo 'Database already exists';
echo 'Creating extensions in hindsight_db database';
psql -h hindsight-db -p 5432 -U hindsight_user -d hindsight_db -c 'CREATE EXTENSION IF NOT EXISTS vector CASCADE;';
psql -h hindsight-db -p 5432 -U hindsight_user -d hindsight_db -c 'CREATE EXTENSION IF NOT EXISTS pg_textsearch CASCADE;';
echo 'Database and extensions created successfully';
"
restart: "no"
networks:
- hindsight-net
hindsight:
image: ghcr.io/vectorize-io/hindsight:${HINDSIGHT_VERSION:-latest}
container_name: hindsight-app
ports:
- "8888:8888"
- "9999:9999"
environment:
# LLM Configuration
HINDSIGHT_API_LLM_PROVIDER: ${HINDSIGHT_API_LLM_PROVIDER:-openai}
HINDSIGHT_API_LLM_API_KEY: ${OPENAI_API_KEY:-your-api-key}
# Database Configuration
HINDSIGHT_API_DATABASE_URL: postgresql://${HINDSIGHT_DB_USER:-hindsight_user}:${HINDSIGHT_DB_PASSWORD:-hindsight_password}@db:5432/${HINDSIGHT_DB_NAME:-hindsight_db}
# Vector and Text Search Extensions
HINDSIGHT_API_VECTOR_EXTENSION: pgvector
HINDSIGHT_API_TEXT_SEARCH_EXTENSION: pg_textsearch
depends_on:
- db
networks:
- hindsight-net
networks:
hindsight-net:
driver: bridge
volumes:
pg_data:
@@ -1,83 +0,0 @@
# Docker Compose file for Hindsight with S3 file storage (SeaweedFS)
#
# SeaweedFS (Apache 2.0) provides an S3-compatible object storage backend
# for storing uploaded files instead of PostgreSQL BYTEA storage.
#
# Make sure to set the required environment variables before running:
# - HINDSIGHT_DB_PASSWORD: Password for the PostgreSQL user
# - Configure LLM provider variables as needed (see below in the hindsight service)
#
# Usage:
# docker compose up -d
#
# Optional environment variables with defaults:
# - HINDSIGHT_VERSION: Hindsight application version (default: latest)
# - HINDSIGHT_DB_USER: PostgreSQL user (default: hindsight_user)
# - HINDSIGHT_DB_NAME: PostgreSQL database name (default: hindsight_db)
# - HINDSIGHT_DB_VERSION: PostgreSQL version (default: 18)
# - SEAWEEDFS_S3_ACCESS_KEY: S3 access key (default: hindsight_s3_key)
# - SEAWEEDFS_S3_SECRET_KEY: S3 secret key (default: hindsight_s3_secret)
services:
db:
image: pgvector/pgvector:pg${HINDSIGHT_DB_VERSION:-18}
container_name: hindsight-db
restart: always
environment:
POSTGRES_USER: ${HINDSIGHT_DB_USER:-hindsight_user}
POSTGRES_PASSWORD: ${HINDSIGHT_DB_PASSWORD:?Please set the HINDSIGHT_DB_PASSWORD env variable}
POSTGRES_DB: ${HINDSIGHT_DB_NAME:-hindsight_db}
volumes:
- pg_data:/var/lib/postgresql/${HINDSIGHT_DB_VERSION:-18}/docker
networks:
- hindsight-net
seaweedfs:
image: chrislusf/seaweedfs:latest
container_name: hindsight-seaweedfs
restart: always
# Single-node mode: master + volume + filer + S3 gateway all in one process
command: >
server
-s3
-s3.port=8333
-s3.config=/etc/seaweedfs/s3.json
-ip.bind=0.0.0.0
volumes:
- seaweedfs_data:/data
- ./s3.json:/etc/seaweedfs/s3.json:ro
# Expose S3 API port (uncomment to access from host)
# ports:
# - "8333:8333"
networks:
- hindsight-net
hindsight:
image: ghcr.io/vectorize-io/hindsight:${HINDSIGHT_VERSION:-latest}
container_name: hindsight-app
ports:
- "8888:8888"
- "9999:9999"
environment:
- HINDSIGHT_API_LLM_API_KEY=${OPENAI_API_KEY?Please set the OPENAI_API_KEY env variable}
- HINDSIGHT_API_DATABASE_URL=postgresql://${HINDSIGHT_DB_USER:-hindsight_user}:${HINDSIGHT_DB_PASSWORD:?Please set the HINDSIGHT_DB_PASSWORD env variable}@db:5432/${HINDSIGHT_DB_NAME:-hindsight_db}
# S3 file storage configuration (SeaweedFS)
- HINDSIGHT_API_FILE_STORAGE_TYPE=s3
- HINDSIGHT_API_FILE_STORAGE_S3_BUCKET=hindsight
- HINDSIGHT_API_FILE_STORAGE_S3_ENDPOINT=http://seaweedfs:8333
- HINDSIGHT_API_FILE_STORAGE_S3_REGION=us-east-1
- HINDSIGHT_API_FILE_STORAGE_S3_ACCESS_KEY_ID=${SEAWEEDFS_S3_ACCESS_KEY:-hindsight_s3_key}
- HINDSIGHT_API_FILE_STORAGE_S3_SECRET_ACCESS_KEY=${SEAWEEDFS_S3_SECRET_KEY:-hindsight_s3_secret}
depends_on:
- db
- seaweedfs
networks:
- hindsight-net
networks:
hindsight-net:
driver: bridge
volumes:
pg_data:
seaweedfs_data:
@@ -1,19 +0,0 @@
{
"identities": [
{
"name": "hindsight",
"credentials": [
{
"accessKey": "hindsight_s3_key",
"secretKey": "hindsight_s3_secret"
}
],
"actions": [
"Admin",
"Read",
"Write",
"List"
]
}
]
}
@@ -1,16 +0,0 @@
# Git
.git
.gitignore
.gitattributes
# Docker
docker-compose.yaml
.dockerignore
# Documentation
README.md
*.md
# Environment
.env
.env.example
@@ -1,25 +0,0 @@
# PostgreSQL Configuration
HINDSIGHT_DB_USER=hindsight_user
HINDSIGHT_DB_PASSWORD=change-me-to-secure-password
HINDSIGHT_DB_NAME=hindsight_db
# Hindsight Version
HINDSIGHT_VERSION=latest
# LLM Configuration
HINDSIGHT_API_LLM_PROVIDER=openai
OPENAI_API_KEY=your-openai-api-key-here
# Alternative LLM providers (uncomment and configure as needed):
# HINDSIGHT_API_LLM_PROVIDER=anthropic
# ANTHROPIC_API_KEY=your-anthropic-api-key
# HINDSIGHT_API_LLM_PROVIDER=gemini
# GEMINI_API_KEY=your-gemini-api-key
# HINDSIGHT_API_LLM_PROVIDER=groq
# GROQ_API_KEY=your-groq-api-key
# Vector and Text Search (already configured in docker-compose.yaml)
# HINDSIGHT_API_VECTOR_EXTENSION=pgvectorscale
# HINDSIGHT_API_TEXT_SEARCH_EXTENSION=pg_textsearch
@@ -1,55 +0,0 @@
# PostgreSQL with pgvector, pgvectorscale, and pg_textsearch extensions
# All three extensions from Timescale/pgvector for high-performance vector and text search
# Note: Requires PostgreSQL 16+
FROM postgres:17
# Install build dependencies and Rust toolchain
RUN apt-get update && apt-get install -y \
build-essential \
git \
postgresql-server-dev-17 \
libpq-dev \
cmake \
curl \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Rust toolchain (required for pgvectorscale)
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Install pgvector (required by pgvectorscale)
RUN cd /tmp && \
git clone --branch v0.8.0 https://github.com/pgvector/pgvector.git && \
cd pgvector && \
make && \
make install && \
rm -rf /tmp/pgvector
# Install cargo-pgrx (PostgreSQL extension framework for Rust)
RUN cargo install cargo-pgrx --version 0.12.5 --locked && \
cargo pgrx init --pg17 /usr/bin/pg_config
# Install pgvectorscale (DiskANN index support)
RUN cd /tmp && \
git clone --branch 0.5.1 https://github.com/timescale/pgvectorscale.git && \
cd pgvectorscale/pgvectorscale && \
cargo pgrx install --release && \
rm -rf /tmp/pgvectorscale
# Install pg_textsearch (BM25 text search)
RUN cd /tmp && \
git clone https://github.com/timescale/pg_textsearch.git && \
cd pg_textsearch && \
make && \
make install && \
rm -rf /tmp/pg_textsearch
# Clean up build dependencies (keep runtime dependencies)
RUN apt-get purge -y --auto-remove git cmake curl && \
rm -rf /root/.cargo/registry /root/.cargo/git
# Ensure extensions are preloaded (pg_textsearch requires preloading)
RUN echo "shared_preload_libraries = 'pg_textsearch'" >> /usr/share/postgresql/postgresql.conf.sample
-101
View File
@@ -1,101 +0,0 @@
# Hindsight with Timescale Extensions
This Docker Compose setup provides a complete Hindsight deployment with **Timescale extensions**:
- **pgvectorscale** - DiskANN algorithm for disk-based scalable vector search
- **pg_textsearch** - High-performance BM25 text search
Both extensions are from [Timescale](https://github.com/timescale) and provide production-grade performance.
## Prerequisites
- Docker and Docker Compose installed
- OpenAI API key (or another LLM provider)
## Quick Start
```bash
# Set environment variables
export HINDSIGHT_DB_PASSWORD="your-secure-password"
export OPENAI_API_KEY="your-openai-api-key"
# Build and start
docker compose -f docker/docker-compose/timescale/docker-compose.yaml up -d --build
# Check logs
docker compose -f docker/docker-compose/timescale/docker-compose.yaml logs -f
```
**Access:**
- API: http://localhost:8888
- Control Plane: http://localhost:9999
## Stop and Clean Up
```bash
# Stop services
docker compose -f docker/docker-compose/timescale/docker-compose.yaml down
# Remove volumes (deletes all data)
docker compose -f docker/docker-compose/timescale/docker-compose.yaml down -v
```
## Configuration
### Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `HINDSIGHT_DB_PASSWORD` | PostgreSQL password | `hindsight_password` |
| `HINDSIGHT_DB_USER` | PostgreSQL username | `hindsight_user` |
| `HINDSIGHT_DB_NAME` | Database name | `hindsight_db` |
| `HINDSIGHT_VERSION` | Hindsight Docker image version | `latest` |
| `OPENAI_API_KEY` | OpenAI API key | (required) |
| `HINDSIGHT_API_LLM_PROVIDER` | LLM provider | `openai` |
### Why Timescale Extensions?
**pgvectorscale (DiskANN):**
- 28x lower p95 latency vs dedicated vector databases
- 16x higher query throughput at 99% recall
- 60-75% cost reduction (disk is cheaper than RAM)
- Best for large datasets (10M+ vectors)
**pg_textsearch (BM25):**
- High-performance keyword retrieval
- Native BM25 ranking algorithm
- Optimized for full-text search
## Troubleshooting
### Extensions not installed
Check if extensions are available:
```bash
docker exec -it hindsight-db-timescale psql -U hindsight_user -d hindsight_db -c "\dx"
```
You should see:
- `vector` (pgvector)
- `vectorscale` (pgvectorscale/DiskANN)
- `pg_textsearch` (BM25 search)
### Build fails
If the Docker build fails during pgvectorscale compilation:
1. Ensure you have sufficient memory (recommended: 4GB+)
2. Check Docker build logs for Rust compilation errors
3. Try building with more resources: `docker compose build --no-cache --memory 4g`
### Port conflicts
If port 5438 is already in use, modify the `ports` section in docker-compose.yaml.
## Learn More
- [pgvectorscale GitHub](https://github.com/timescale/pgvectorscale)
- [pg_textsearch GitHub](https://github.com/timescale/pg_textsearch)
- [HNSW vs DiskANN](https://www.tigerdata.com/learn/hnsw-vs-diskann)
- [Hindsight Documentation](https://hindsight.dev)
@@ -1,108 +0,0 @@
name: hindsight
# Docker Compose file for Hindsight with Timescale extensions
# - pgvectorscale: DiskANN vector search (disk-based, scalable)
# - pg_textsearch: BM25 text search (high-performance keyword retrieval)
#
# Quick start:
# docker compose -f docker/docker-compose/timescale/docker-compose.yaml up -d --build
#
# Required environment variables:
# - HINDSIGHT_DB_PASSWORD: Password for the PostgreSQL user
# - OPENAI_API_KEY (or configure another LLM provider)
#
# Optional environment variables with defaults:
# - HINDSIGHT_VERSION: Hindsight application version (default: latest)
# - HINDSIGHT_DB_USER: PostgreSQL user (default: hindsight_user)
# - HINDSIGHT_DB_NAME: PostgreSQL database name (default: hindsight_db)
services:
db:
# Custom PostgreSQL image with Timescale extensions (pgvectorscale + pg_textsearch)
build:
context: .
dockerfile: Dockerfile
container_name: hindsight-db-timescale
restart: always
# Expose PostgreSQL port (using 5438 to avoid conflicts with other setups)
ports:
- "5438:5432"
environment:
POSTGRES_USER: ${HINDSIGHT_DB_USER:-hindsight_user}
POSTGRES_PASSWORD: ${HINDSIGHT_DB_PASSWORD:-hindsight_password}
POSTGRES_DB: ${HINDSIGHT_DB_NAME:-hindsight_db}
volumes:
- pg_data:/var/lib/postgresql/data
networks:
- hindsight-net
# Health check to ensure database is ready
healthcheck:
test: ["CMD-SHELL", "pg_isready -U hindsight_user"]
interval: 5s
timeout: 5s
retries: 5
timescale-init:
build:
context: .
dockerfile: Dockerfile
depends_on:
db:
condition: service_healthy
environment:
- PGPASSWORD=${HINDSIGHT_DB_PASSWORD:-hindsight_password}
command: >
bash -c "
echo 'PostgreSQL is ready - creating hindsight_db database';
psql -h hindsight-db-timescale -p 5432 -U hindsight_user -c 'CREATE DATABASE hindsight_db;' 2>/dev/null || echo 'Database already exists';
echo 'Installing Timescale extensions...';
echo '1/3: Installing pgvector (required by pgvectorscale)...';
psql -h hindsight-db-timescale -p 5432 -U hindsight_user -d hindsight_db -c 'CREATE EXTENSION IF NOT EXISTS vector CASCADE;';
echo '2/3: Installing pgvectorscale (DiskANN vector search)...';
psql -h hindsight-db-timescale -p 5432 -U hindsight_user -d hindsight_db -c 'CREATE EXTENSION IF NOT EXISTS vectorscale CASCADE;';
echo '3/3: Installing pg_textsearch (BM25 text search)...';
psql -h hindsight-db-timescale -p 5432 -U hindsight_user -d hindsight_db -c 'CREATE EXTENSION IF NOT EXISTS pg_textsearch CASCADE;';
echo '';
echo '✅ Timescale extensions installed successfully';
echo '';
echo 'Installed extensions:';
psql -h hindsight-db-timescale -p 5432 -U hindsight_user -d hindsight_db -c \"\\dx\" | grep -E '(vector|vectorscale|pg_textsearch)';
"
restart: "no"
networks:
- hindsight-net
hindsight:
image: ghcr.io/vectorize-io/hindsight:${HINDSIGHT_VERSION:-latest}
container_name: hindsight-app-timescale
ports:
- "8888:8888"
- "9999:9999"
environment:
# LLM Configuration
HINDSIGHT_API_LLM_PROVIDER: ${HINDSIGHT_API_LLM_PROVIDER:-openai}
HINDSIGHT_API_LLM_API_KEY: ${OPENAI_API_KEY:-your-api-key}
# Database Configuration
HINDSIGHT_API_DATABASE_URL: postgresql://${HINDSIGHT_DB_USER:-hindsight_user}:${HINDSIGHT_DB_PASSWORD:-hindsight_password}@db:5432/${HINDSIGHT_DB_NAME:-hindsight_db}
# Timescale Extensions
# pgvectorscale: DiskANN algorithm for disk-based scalable vector search
HINDSIGHT_API_VECTOR_EXTENSION: pgvectorscale
# pg_textsearch: High-performance BM25 text search
HINDSIGHT_API_TEXT_SEARCH_EXTENSION: pg_textsearch
depends_on:
db:
condition: service_healthy
timescale-init:
condition: service_completed_successfully
networks:
- hindsight-net
networks:
hindsight-net:
driver: bridge
volumes:
pg_data:
+2 -2
View File
@@ -2,8 +2,8 @@ apiVersion: v2
name: hindsight
description: Hindsight helm chart
type: application
version: 0.4.11
appVersion: "0.4.11"
version: 0.4.10
appVersion: "0.4.10"
keywords:
- ai
- memory
+1 -1
View File
@@ -46,4 +46,4 @@ __all__ = [
"RemoteTEICrossEncoder",
"LLMConfig",
]
__version__ = "0.4.11"
__version__ = "0.4.10"
@@ -24,35 +24,14 @@ depends_on: str | Sequence[str] | None = None
def _detect_vector_extension() -> str:
"""
Detect or validate vector extension: 'pgvector', 'vchord', or 'pgvectorscale'.
Detect or validate vector extension: 'vchord' or 'pgvector'.
Respects HINDSIGHT_API_VECTOR_EXTENSION env var if set.
"""
conn = op.get_bind()
vector_extension = os.getenv("HINDSIGHT_API_VECTOR_EXTENSION", "pgvector").lower()
# Validate configured extension is installed
if vector_extension == "pgvectorscale":
# pgvectorscale/DiskANN requires pgvector
pgvector_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vector'")).scalar()
if not pgvector_check:
raise RuntimeError(
"DiskANN requires pgvector. Install with: CREATE EXTENSION vector; then vectorscale or pg_diskann CASCADE;"
)
# Check for either vectorscale (open source) or pg_diskann (Azure)
vectorscale_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vectorscale'")).scalar()
pg_diskann_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'pg_diskann'")).scalar()
if vectorscale_check:
return "pgvectorscale"
elif pg_diskann_check:
return "pg_diskann"
else:
raise RuntimeError(
"Configured vector extension 'pgvectorscale' not found. Install either:\n"
" - pgvectorscale: CREATE EXTENSION vectorscale CASCADE;\n"
" - pg_diskann (Azure): CREATE EXTENSION pg_diskann CASCADE;"
)
elif vector_extension == "vchord":
if vector_extension == "vchord":
vchord_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vchord'")).scalar()
if not vchord_check:
raise RuntimeError(
@@ -67,14 +46,12 @@ def _detect_vector_extension() -> str:
)
return "pgvector"
else:
raise ValueError(
f"Invalid HINDSIGHT_API_VECTOR_EXTENSION: {vector_extension}. Must be 'pgvector', 'vchord', or 'pgvectorscale'"
)
raise ValueError(f"Invalid HINDSIGHT_API_VECTOR_EXTENSION: {vector_extension}. Must be 'pgvector' or 'vchord'")
def _detect_text_search_extension() -> str:
"""
Detect or validate text search extension: 'native', 'vchord', or 'pg_textsearch'.
Detect or validate text search extension: 'native' or 'vchord'.
Respects HINDSIGHT_API_TEXT_SEARCH_EXTENSION env var.
Creates the extension if needed.
"""
@@ -92,23 +69,11 @@ def _detect_text_search_extension() -> str:
# Extension truly doesn't exist - re-raise the error
raise
return "vchord"
elif text_search_extension == "pg_textsearch":
# Create pg_textsearch extension if not exists
try:
op.execute("CREATE EXTENSION IF NOT EXISTS pg_textsearch CASCADE")
except Exception:
# Extension might already exist or user lacks permissions - verify it exists
conn = op.get_bind()
result = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'pg_textsearch'")).fetchone()
if not result:
# Extension truly doesn't exist - re-raise the error
raise
return "pg_textsearch"
elif text_search_extension == "native":
return "native"
else:
raise ValueError(
f"Invalid HINDSIGHT_API_TEXT_SEARCH_EXTENSION: {text_search_extension}. Must be 'native', 'vchord', or 'pg_textsearch'"
f"Invalid HINDSIGHT_API_TEXT_SEARCH_EXTENSION: {text_search_extension}. Must be 'native' or 'vchord'"
)
@@ -267,12 +232,6 @@ def upgrade() -> None:
ALTER TABLE memory_units
ADD COLUMN search_vector bm25_catalog.bm25vector
""")
elif text_search_ext == "pg_textsearch":
# Timescale pg_textsearch: dummy TEXT column for consistency (indexes operate on base columns directly)
op.execute("""
ALTER TABLE memory_units
ADD COLUMN search_vector TEXT
""")
else: # native
# Native PostgreSQL: tsvector with automatic generation
op.execute("""
@@ -312,21 +271,7 @@ def upgrade() -> None:
# Create vector index - conditional based on available extension
vector_ext = _detect_vector_extension()
if vector_ext == "pgvectorscale":
# Use DiskANN index for pgvectorscale (disk-based, scalable)
op.execute("""
CREATE INDEX idx_memory_units_embedding ON memory_units
USING diskann (embedding vector_cosine_ops)
WITH (num_neighbors = 50)
""")
elif vector_ext == "pg_diskann":
# Use DiskANN index for pg_diskann (Azure)
op.execute("""
CREATE INDEX idx_memory_units_embedding ON memory_units
USING diskann (embedding vector_cosine_ops)
WITH (max_neighbors = 50)
""")
elif vector_ext == "vchord":
if vector_ext == "vchord":
# Use vchordrq index for vchord (supports high-dimensional embeddings)
op.execute("""
CREATE INDEX idx_memory_units_embedding ON memory_units
@@ -350,14 +295,6 @@ def upgrade() -> None:
CREATE INDEX idx_memory_units_text_search ON memory_units
USING bm25 (search_vector bm25_catalog.bm25_ops)
""")
elif text_search_ext == "pg_textsearch":
# Timescale pg_textsearch BM25 index on text column
# Note: pg_textsearch doesn't support expressions, so we index the main text column
op.execute("""
CREATE INDEX idx_memory_units_text_search ON memory_units
USING bm25(text)
WITH (text_config='english')
""")
else: # native
# Native PostgreSQL GIN index
op.execute("""
@@ -1,70 +0,0 @@
"""Add file_storage table for BYTEA-based file storage
Revision ID: a1b2c3d4e5f6
Revises: y0t1u2v3w4x5
Create Date: 2026-02-16
Creates a dedicated table for storing uploaded files using BYTEA.
This provides zero-config file storage that "just works" for development
and small deployments. For production/scale, use S3-compatible storage.
Files are stored in a separate table to avoid bloating the documents table.
"""
from collections.abc import Sequence
from alembic import context, op
revision: str = "a1b2c3d4e5f6"
down_revision: str | Sequence[str] | None = "y0t1u2v3w4x5"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def _get_schema_prefix() -> str:
"""Get schema prefix for table names (required for multi-tenant support)."""
schema = context.config.get_main_option("target_schema")
return f'"{schema}".' if schema else ""
def upgrade() -> None:
"""Create file_storage table for BYTEA storage."""
schema = _get_schema_prefix()
# Create file_storage table (minimal: just key + data)
op.execute(
f"""
CREATE TABLE {schema}file_storage (
storage_key TEXT PRIMARY KEY,
data BYTEA NOT NULL
)
"""
)
# Add file tracking columns to documents table
op.execute(
f"""
ALTER TABLE {schema}documents
ADD COLUMN IF NOT EXISTS file_storage_key TEXT,
ADD COLUMN IF NOT EXISTS file_original_name TEXT,
ADD COLUMN IF NOT EXISTS file_content_type TEXT
"""
)
def downgrade() -> None:
"""Remove file_storage table and related columns."""
schema = _get_schema_prefix()
# Drop columns from documents table
op.execute(
f"""
ALTER TABLE {schema}documents
DROP COLUMN IF EXISTS file_storage_key,
DROP COLUMN IF EXISTS file_original_name,
DROP COLUMN IF EXISTS file_content_type
"""
)
# Drop file_storage table
op.execute(f"DROP TABLE IF EXISTS {schema}file_storage")
@@ -31,35 +31,14 @@ def _get_schema_prefix() -> str:
def _detect_vector_extension() -> str:
"""
Detect or validate vector extension: 'pgvector', 'vchord', or 'pgvectorscale'.
Detect or validate vector extension: 'vchord' or 'pgvector'.
Respects HINDSIGHT_API_VECTOR_EXTENSION env var if set.
"""
conn = op.get_bind()
vector_extension = os.getenv("HINDSIGHT_API_VECTOR_EXTENSION", "pgvector").lower()
# Validate configured extension is installed
if vector_extension == "pgvectorscale":
# pgvectorscale/DiskANN requires pgvector
pgvector_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vector'")).scalar()
if not pgvector_check:
raise RuntimeError(
"DiskANN requires pgvector. Install with: CREATE EXTENSION vector; then vectorscale or pg_diskann CASCADE;"
)
# Check for either vectorscale (open source) or pg_diskann (Azure)
vectorscale_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vectorscale'")).scalar()
pg_diskann_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'pg_diskann'")).scalar()
if vectorscale_check:
return "pgvectorscale"
elif pg_diskann_check:
return "pg_diskann"
else:
raise RuntimeError(
"Configured vector extension 'pgvectorscale' not found. Install either:\n"
" - pgvectorscale: CREATE EXTENSION vectorscale CASCADE;\n"
" - pg_diskann (Azure): CREATE EXTENSION pg_diskann CASCADE;"
)
elif vector_extension == "vchord":
if vector_extension == "vchord":
vchord_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vchord'")).scalar()
if not vchord_check:
raise RuntimeError(
@@ -74,14 +53,12 @@ def _detect_vector_extension() -> str:
)
return "pgvector"
else:
raise ValueError(
f"Invalid HINDSIGHT_API_VECTOR_EXTENSION: {vector_extension}. Must be 'pgvector', 'vchord', or 'pgvectorscale'"
)
raise ValueError(f"Invalid HINDSIGHT_API_VECTOR_EXTENSION: {vector_extension}. Must be 'pgvector' or 'vchord'")
def _detect_text_search_extension() -> str:
"""
Detect or validate text search extension: 'native', 'vchord', or 'pg_textsearch'.
Detect or validate text search extension: 'native' or 'vchord'.
Respects HINDSIGHT_API_TEXT_SEARCH_EXTENSION env var.
Creates the extension if needed.
"""
@@ -99,23 +76,11 @@ def _detect_text_search_extension() -> str:
# Extension truly doesn't exist - re-raise the error
raise
return "vchord"
elif text_search_extension == "pg_textsearch":
# Create pg_textsearch extension if not exists
try:
op.execute("CREATE EXTENSION IF NOT EXISTS pg_textsearch CASCADE")
except Exception:
# Extension might already exist or user lacks permissions - verify it exists
conn = op.get_bind()
result = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'pg_textsearch'")).fetchone()
if not result:
# Extension truly doesn't exist - re-raise the error
raise
return "pg_textsearch"
elif text_search_extension == "native":
return "native"
else:
raise ValueError(
f"Invalid HINDSIGHT_API_TEXT_SEARCH_EXTENSION: {text_search_extension}. Must be 'native', 'vchord', or 'pg_textsearch'"
f"Invalid HINDSIGHT_API_TEXT_SEARCH_EXTENSION: {text_search_extension}. Must be 'native' or 'vchord'"
)
@@ -157,19 +122,7 @@ def upgrade() -> None:
op.execute(f"CREATE INDEX idx_learnings_bank_id ON {schema}learnings(bank_id)")
# Create vector index based on detected extension
if vector_ext == "pgvectorscale":
op.execute(f"""
CREATE INDEX idx_learnings_embedding ON {schema}learnings
USING diskann (embedding vector_cosine_ops)
WITH (num_neighbors = 50)
""")
elif vector_ext == "pg_diskann":
op.execute(f"""
CREATE INDEX idx_learnings_embedding ON {schema}learnings
USING diskann (embedding vector_cosine_ops)
WITH (max_neighbors = 50)
""")
elif vector_ext == "vchord":
if vector_ext == "vchord":
op.execute(f"""
CREATE INDEX idx_learnings_embedding ON {schema}learnings
USING vchordrq (embedding vector_l2_ops)
@@ -193,15 +146,6 @@ def upgrade() -> None:
CREATE INDEX idx_learnings_text_search ON {schema}learnings
USING bm25 (search_vector bm25_catalog.bm25_ops)
""")
elif text_search_ext == "pg_textsearch":
# Timescale pg_textsearch: dummy TEXT column for consistency (indexes operate on base columns directly)
op.execute(f"""
ALTER TABLE {schema}learnings ADD COLUMN search_vector TEXT
""")
op.execute(f"""
CREATE INDEX idx_learnings_text_search ON {schema}learnings
USING bm25(text) WITH (text_config='english')
""")
else: # native
# Native PostgreSQL: tsvector with automatic generation
op.execute(f"""
@@ -236,19 +180,7 @@ def upgrade() -> None:
op.execute(f"CREATE INDEX idx_pinned_reflections_bank_id ON {schema}pinned_reflections(bank_id)")
# Create vector index based on detected extension
if vector_ext == "pgvectorscale":
op.execute(f"""
CREATE INDEX idx_pinned_reflections_embedding ON {schema}pinned_reflections
USING diskann (embedding vector_cosine_ops)
WITH (num_neighbors = 50)
""")
elif vector_ext == "pg_diskann":
op.execute(f"""
CREATE INDEX idx_pinned_reflections_embedding ON {schema}pinned_reflections
USING diskann (embedding vector_cosine_ops)
WITH (max_neighbors = 50)
""")
elif vector_ext == "vchord":
if vector_ext == "vchord":
op.execute(f"""
CREATE INDEX idx_pinned_reflections_embedding ON {schema}pinned_reflections
USING vchordrq (embedding vector_l2_ops)
@@ -272,16 +204,6 @@ def upgrade() -> None:
CREATE INDEX idx_pinned_reflections_text_search ON {schema}pinned_reflections
USING bm25 (search_vector bm25_catalog.bm25_ops)
""")
elif text_search_ext == "pg_textsearch":
# Timescale pg_textsearch: dummy TEXT column for consistency (indexes operate on base columns directly)
op.execute(f"""
ALTER TABLE {schema}pinned_reflections ADD COLUMN search_vector TEXT
""")
op.execute(f"""
CREATE INDEX idx_pinned_reflections_text_search ON {schema}pinned_reflections
USING bm25(content)
WITH (text_config='english')
""")
else: # native
# Native PostgreSQL: tsvector with automatic generation
op.execute(f"""
@@ -1,49 +0,0 @@
"""Add GIN index on async_operations.result_metadata for parent_operation_id queries
Revision ID: y0t1u2v3w4x5
Revises: x9s0t1u2v3w4
Create Date: 2026-02-13
This migration adds a GIN index on the result_metadata JSONB column in the
async_operations table to support efficient queries for child operations by
parent_operation_id.
The index enables fast lookups when querying for child operations:
SELECT * FROM async_operations
WHERE result_metadata::jsonb @> '{"parent_operation_id": "uuid"}'::jsonb
"""
from collections.abc import Sequence
from alembic import context, op
revision: str = "y0t1u2v3w4x5"
down_revision: str | Sequence[str] | None = "x9s0t1u2v3w4"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def _get_schema_prefix() -> str:
"""Get schema prefix for table names (required for multi-tenant support)."""
schema = context.config.get_main_option("target_schema")
return f'"{schema}".' if schema else ""
def upgrade() -> None:
"""Add GIN index on result_metadata for efficient parent_operation_id queries."""
schema = _get_schema_prefix()
# Add GIN index for JSONB containment queries (@> operator)
op.execute(f"""
CREATE INDEX idx_async_operations_result_metadata
ON {schema}async_operations
USING gin(result_metadata)
""")
def downgrade() -> None:
"""Remove GIN index on result_metadata."""
schema = _get_schema_prefix()
# Drop index
op.execute(f"DROP INDEX IF EXISTS {schema}idx_async_operations_result_metadata")
+2 -228
View File
@@ -13,7 +13,7 @@ from contextlib import asynccontextmanager
from datetime import datetime
from typing import Any, Literal
from fastapi import Depends, FastAPI, File, Form, Header, HTTPException, Query, UploadFile
from fastapi import Depends, FastAPI, Header, HTTPException, Query
from hindsight_api.extensions import AuthenticationError
@@ -430,36 +430,6 @@ class RetainRequest(BaseModel):
)
class FileRetainMetadata(BaseModel):
"""Metadata for a single file in file retain request."""
document_id: str | None = Field(default=None, description="Document ID (auto-generated if not provided)")
context: str | None = Field(default=None, description="Context for the file")
metadata: dict[str, Any] | None = Field(default=None, description="Additional metadata")
tags: list[str] | None = Field(default=None, description="Tags for this file")
timestamp: str | None = Field(default=None, description="ISO timestamp")
class FileRetainRequest(BaseModel):
"""Request model for file retain endpoint."""
model_config = ConfigDict(
json_schema_extra={
"example": {
"files_metadata": [
{"document_id": "report_2024", "tags": ["quarterly"]},
{"context": "meeting notes"},
],
}
}
)
files_metadata: list[FileRetainMetadata] | None = Field(
default=None,
description="Metadata for each file (optional, must match number of files if provided)",
)
class RetainResponse(BaseModel):
"""Response model for retain endpoint."""
@@ -484,7 +454,7 @@ class RetainResponse(BaseModel):
)
operation_id: str | None = Field(
default=None,
description="Operation ID for tracking async operations. Use GET /v1/default/banks/{bank_id}/operations to list operations. Only present when async=true.",
description="Operation ID for tracking async operations. Use GET /v1/default/banks/{bank_id}/operations to list operations and find this ID. Only present when async=true.",
)
usage: TokenUsage | None = Field(
default=None,
@@ -492,26 +462,6 @@ class RetainResponse(BaseModel):
)
class FileRetainResponse(BaseModel):
"""Response model for file upload endpoint."""
model_config = ConfigDict(
json_schema_extra={
"example": {
"operation_ids": [
"550e8400-e29b-41d4-a716-446655440000",
"550e8400-e29b-41d4-a716-446655440001",
"550e8400-e29b-41d4-a716-446655440002",
],
}
},
)
operation_ids: list[str] = Field(
description="Operation IDs for tracking file conversion operations. Use GET /v1/default/banks/{bank_id}/operations to list operations."
)
class FactsIncludeOptions(BaseModel):
"""Options for including facts (based_on) in reflect results."""
@@ -1407,16 +1357,6 @@ class CancelOperationResponse(BaseModel):
operation_id: str
class ChildOperationStatus(BaseModel):
"""Status of a child operation (for batch operations)."""
operation_id: str
status: str
sub_batch_index: int | None = None
items_count: int | None = None
error_message: str | None = None
class OperationStatusResponse(BaseModel):
"""Response model for getting a single operation status."""
@@ -1441,13 +1381,6 @@ class OperationStatusResponse(BaseModel):
updated_at: str | None = None
completed_at: str | None = None
error_message: str | None = None
result_metadata: dict[str, Any] | None = Field(
default=None,
description="Internal metadata for debugging. Structure may change without notice. Not for production use.",
)
child_operations: list[ChildOperationStatus] | None = Field(
default=None, description="Child operations for batch operations (if applicable)"
)
class AsyncOperationSubmitResponse(BaseModel):
@@ -1473,7 +1406,6 @@ class FeaturesInfo(BaseModel):
mcp: bool = Field(description="Whether MCP (Model Context Protocol) server is enabled")
worker: bool = Field(description="Whether the background worker is enabled")
bank_config_api: bool = Field(description="Whether per-bank configuration API is enabled")
file_upload_api: bool = Field(description="Whether file upload/conversion API is enabled")
class VersionResponse(BaseModel):
@@ -1488,7 +1420,6 @@ class VersionResponse(BaseModel):
"mcp": True,
"worker": True,
"bank_config_api": False,
"file_upload_api": True,
},
}
}
@@ -1783,7 +1714,6 @@ def _register_routes(app: FastAPI):
mcp=config.mcp_enabled,
worker=config.worker_enabled,
bank_config_api=config.enable_bank_config_api,
file_upload_api=config.enable_file_upload_api,
),
)
@@ -3633,21 +3563,6 @@ def _register_routes(app: FastAPI):
}
)
else:
# Check if batch API is enabled - if so, require async mode
from hindsight_api.config import get_config
config = get_config()
if config.retain_batch_enabled:
raise HTTPException(
status_code=400,
detail=(
"Batch API is enabled (HINDSIGHT_API_RETAIN_BATCH_ENABLED=true) but async=false. "
"Batch operations can take several minutes to hours and will timeout in synchronous mode. "
"Please set async=true in your request to use background processing, or disable batch API "
"by setting HINDSIGHT_API_RETAIN_BATCH_ENABLED=false in your environment."
),
)
# Synchronous processing: wait for completion (record metrics)
with metrics.record_operation("retain", bank_id=bank_id, source="api"):
result, usage = await app.state.memory.retain_batch_async(
@@ -3685,147 +3600,6 @@ def _register_routes(app: FastAPI):
logger.error(f"Error in /v1/default/banks/{bank_id}/memories (retain): {error_detail}")
raise HTTPException(status_code=500, detail=str(e))
@app.post(
"/v1/default/banks/{bank_id}/files/retain",
response_model=FileRetainResponse,
summary="Convert files to memories",
description="Upload files (PDF, DOCX, etc.), convert them to markdown, and retain as memories.\n\n"
"This endpoint handles file upload, conversion, and memory creation in a single operation.\n\n"
"**Features:**\n"
"- Supports PDF, DOCX, PPTX, XLSX, images (with OCR), audio (with transcription)\n"
"- Automatic file-to-markdown conversion using pluggable parsers\n"
"- Files stored in object storage (PostgreSQL by default, S3 for production)\n"
"- Each file becomes a separate document with optional metadata/tags\n"
"- Always processes asynchronously — returns operation IDs immediately\n\n"
"**The system automatically:**\n"
"1. Stores uploaded files in object storage\n"
"2. Converts files to markdown\n"
"3. Creates document records with file metadata\n"
"4. Extracts facts and creates memory units (same as regular retain)\n\n"
"Use the operations endpoint to monitor progress.\n\n"
"**Request format:** multipart/form-data with:\n"
"- `files`: One or more files to upload\n"
"- `request`: JSON string with FileRetainRequest model (files_metadata)\n\n"
"**Note:** File parser is configured server-side via `HINDSIGHT_API_FILE_PARSER` (default: markitdown).",
operation_id="file_retain",
tags=["Files"],
)
async def api_file_retain(
bank_id: str,
files: list[UploadFile] = File(..., description="Files to upload and convert"),
request: str = Form(..., description="JSON string with FileRetainRequest model"),
request_context: RequestContext = Depends(get_request_context),
):
"""Upload and convert files to memories."""
from hindsight_api.config import get_config
config = get_config()
# Check if file upload API is enabled
if not config.enable_file_upload_api:
raise HTTPException(
status_code=404,
detail="File upload API is disabled. Set HINDSIGHT_API_ENABLE_FILE_UPLOAD_API=true to enable.",
)
try:
# Parse request JSON
try:
request_data = FileRetainRequest.model_validate_json(request)
except Exception as e:
raise HTTPException(
status_code=400,
detail=f"Invalid request JSON: {str(e)}",
)
# Validate file count
if len(files) > config.file_conversion_max_batch_size:
raise HTTPException(
status_code=400,
detail=f"Too many files. Maximum {config.file_conversion_max_batch_size} files per request.",
)
# Validate files_metadata count matches files count if provided
if request_data.files_metadata and len(request_data.files_metadata) != len(files):
raise HTTPException(
status_code=400,
detail=f"files_metadata count ({len(request_data.files_metadata)}) must match files count ({len(files)})",
)
# Prepare file items and calculate total batch size
file_items = []
total_batch_size = 0
for i, file in enumerate(files):
# Read file content to check size
file_content = await file.read()
size = len(file_content)
total_batch_size += size
# Create a temporary file-like object from the bytes
import io
file_obj = io.BytesIO(file_content)
# Create a mock UploadFile with the necessary attributes
class FileWrapper:
def __init__(self, content, filename, content_type):
self._content = content
self.filename = filename
self.content_type = content_type
self._buffer = io.BytesIO(content)
async def read(self):
return self._content
wrapped_file = FileWrapper(file_content, file.filename, file.content_type)
# Get per-file metadata
file_meta = request_data.files_metadata[i] if request_data.files_metadata else FileRetainMetadata()
doc_id = file_meta.document_id or f"file_{uuid.uuid4()}"
item = {
"file": wrapped_file,
"document_id": doc_id,
"context": file_meta.context,
"metadata": file_meta.metadata or {},
"tags": file_meta.tags or [],
"timestamp": file_meta.timestamp,
}
file_items.append(item)
# Check total batch size after processing all files
if total_batch_size > config.file_conversion_max_batch_size_bytes:
total_mb = total_batch_size / (1024 * 1024)
raise HTTPException(
status_code=400,
detail=f"Total batch size ({total_mb:.1f}MB) exceeds maximum of {config.file_conversion_max_batch_size_mb}MB",
)
result = await app.state.memory.submit_async_file_retain(
bank_id=bank_id,
file_items=file_items,
parser=config.file_parser,
document_tags=None,
request_context=request_context,
)
return FileRetainResponse.model_validate(
{
"operation_ids": result["operation_ids"],
}
)
except OperationValidationError as e:
raise HTTPException(status_code=e.status_code, detail=e.reason)
except (AuthenticationError, HTTPException):
raise
except Exception as e:
import traceback
error_detail = f"{str(e)}\n\nTraceback:\n{traceback.format_exc()}"
logger.error(f"Error in /v1/default/banks/{bank_id}/files/retain: {error_detail}")
raise HTTPException(status_code=500, detail=str(e))
@app.delete(
"/v1/default/banks/{bank_id}/memories",
response_model=DeleteResponse,
-4
View File
@@ -86,8 +86,6 @@ def print_startup_info(
reranker_provider: str,
mcp_enabled: bool = False,
version: str | None = None,
vector_extension: str | None = None,
text_search_extension: str | None = None,
):
"""Print styled startup information."""
print(color_start("Starting Hindsight API..."))
@@ -98,8 +96,6 @@ def print_startup_info(
print(f" {dim('LLM:')} {color(f'{llm_provider} / {llm_model}', 0.6)}")
print(f" {dim('Embeddings:')} {color(embeddings_provider, 0.8)}")
print(f" {dim('Reranker:')} {color(reranker_provider, 1.0)}")
extensions = f"{vector_extension or 'default'} (vector) / {text_search_extension or 'default'} (text)"
print(f" {dim('Extensions:')} {color(extensions, 0.4)}")
if mcp_enabled:
print(f" {dim('MCP:')} {color_end('enabled at /mcp')}")
print()
+6 -137
View File
@@ -129,11 +129,6 @@ ENV_LLM_INITIAL_BACKOFF = "HINDSIGHT_API_LLM_INITIAL_BACKOFF"
ENV_LLM_MAX_BACKOFF = "HINDSIGHT_API_LLM_MAX_BACKOFF"
ENV_LLM_TIMEOUT = "HINDSIGHT_API_LLM_TIMEOUT"
ENV_LLM_GROQ_SERVICE_TIER = "HINDSIGHT_API_LLM_GROQ_SERVICE_TIER"
ENV_LLM_OPENAI_SERVICE_TIER = "HINDSIGHT_API_LLM_OPENAI_SERVICE_TIER"
# Defaults for service tiers
DEFAULT_LLM_GROQ_SERVICE_TIER = "auto" # "on_demand", "flex", or "auto"
DEFAULT_LLM_OPENAI_SERVICE_TIER = None # None (default) or "flex" (50% cheaper)
# Per-operation LLM configuration (optional, falls back to global LLM config)
ENV_RETAIN_LLM_PROVIDER = "HINDSIGHT_API_RETAIN_LLM_PROVIDER"
@@ -194,14 +189,6 @@ ENV_RERANKER_LITELLM_API_BASE = "HINDSIGHT_API_RERANKER_LITELLM_API_BASE"
ENV_RERANKER_LITELLM_API_KEY = "HINDSIGHT_API_RERANKER_LITELLM_API_KEY"
ENV_RERANKER_LITELLM_MODEL = "HINDSIGHT_API_RERANKER_LITELLM_MODEL"
# LiteLLM SDK configuration (direct API access, no proxy needed)
ENV_EMBEDDINGS_LITELLM_SDK_API_KEY = "HINDSIGHT_API_EMBEDDINGS_LITELLM_SDK_API_KEY"
ENV_EMBEDDINGS_LITELLM_SDK_MODEL = "HINDSIGHT_API_EMBEDDINGS_LITELLM_SDK_MODEL"
ENV_EMBEDDINGS_LITELLM_SDK_API_BASE = "HINDSIGHT_API_EMBEDDINGS_LITELLM_SDK_API_BASE"
ENV_RERANKER_LITELLM_SDK_API_KEY = "HINDSIGHT_API_RERANKER_LITELLM_SDK_API_KEY"
ENV_RERANKER_LITELLM_SDK_MODEL = "HINDSIGHT_API_RERANKER_LITELLM_SDK_MODEL"
ENV_RERANKER_LITELLM_SDK_API_BASE = "HINDSIGHT_API_RERANKER_LITELLM_SDK_API_BASE"
# Deprecated: Legacy shared LiteLLM config (for backward compatibility)
ENV_LITELLM_API_BASE = "HINDSIGHT_API_LITELLM_API_BASE"
ENV_LITELLM_API_KEY = "HINDSIGHT_API_LITELLM_API_KEY"
@@ -255,27 +242,6 @@ ENV_RETAIN_CHUNK_SIZE = "HINDSIGHT_API_RETAIN_CHUNK_SIZE"
ENV_RETAIN_EXTRACT_CAUSAL_LINKS = "HINDSIGHT_API_RETAIN_EXTRACT_CAUSAL_LINKS"
ENV_RETAIN_EXTRACTION_MODE = "HINDSIGHT_API_RETAIN_EXTRACTION_MODE"
ENV_RETAIN_CUSTOM_INSTRUCTIONS = "HINDSIGHT_API_RETAIN_CUSTOM_INSTRUCTIONS"
ENV_RETAIN_BATCH_TOKENS = "HINDSIGHT_API_RETAIN_BATCH_TOKENS"
ENV_RETAIN_BATCH_ENABLED = "HINDSIGHT_API_RETAIN_BATCH_ENABLED"
ENV_RETAIN_BATCH_POLL_INTERVAL_SECONDS = "HINDSIGHT_API_RETAIN_BATCH_POLL_INTERVAL_SECONDS"
# File storage configuration
ENV_FILE_STORAGE_TYPE = "HINDSIGHT_API_FILE_STORAGE_TYPE"
ENV_FILE_STORAGE_S3_BUCKET = "HINDSIGHT_API_FILE_STORAGE_S3_BUCKET"
ENV_FILE_STORAGE_S3_REGION = "HINDSIGHT_API_FILE_STORAGE_S3_REGION"
ENV_FILE_STORAGE_S3_ENDPOINT = "HINDSIGHT_API_FILE_STORAGE_S3_ENDPOINT"
ENV_FILE_STORAGE_S3_ACCESS_KEY_ID = "HINDSIGHT_API_FILE_STORAGE_S3_ACCESS_KEY_ID"
ENV_FILE_STORAGE_S3_SECRET_ACCESS_KEY = "HINDSIGHT_API_FILE_STORAGE_S3_SECRET_ACCESS_KEY"
ENV_FILE_STORAGE_GCS_BUCKET = "HINDSIGHT_API_FILE_STORAGE_GCS_BUCKET"
ENV_FILE_STORAGE_GCS_SERVICE_ACCOUNT_KEY = "HINDSIGHT_API_FILE_STORAGE_GCS_SERVICE_ACCOUNT_KEY"
ENV_FILE_STORAGE_AZURE_CONTAINER = "HINDSIGHT_API_FILE_STORAGE_AZURE_CONTAINER"
ENV_FILE_STORAGE_AZURE_ACCOUNT_NAME = "HINDSIGHT_API_FILE_STORAGE_AZURE_ACCOUNT_NAME"
ENV_FILE_STORAGE_AZURE_ACCOUNT_KEY = "HINDSIGHT_API_FILE_STORAGE_AZURE_ACCOUNT_KEY"
ENV_FILE_PARSER = "HINDSIGHT_API_FILE_PARSER"
ENV_FILE_CONVERSION_MAX_BATCH_SIZE_MB = "HINDSIGHT_API_FILE_CONVERSION_MAX_BATCH_SIZE_MB"
ENV_FILE_CONVERSION_MAX_BATCH_SIZE = "HINDSIGHT_API_FILE_CONVERSION_MAX_BATCH_SIZE"
ENV_ENABLE_FILE_UPLOAD_API = "HINDSIGHT_API_ENABLE_FILE_UPLOAD_API"
ENV_FILE_DELETE_AFTER_RETAIN = "HINDSIGHT_API_FILE_DELETE_AFTER_RETAIN"
# Observations settings (consolidated knowledge from facts)
ENV_ENABLE_OBSERVATIONS = "HINDSIGHT_API_ENABLE_OBSERVATIONS"
@@ -360,21 +326,17 @@ DEFAULT_RERANKER_FLASHRANK_CACHE_DIR = None # Use default cache directory
DEFAULT_EMBEDDINGS_COHERE_MODEL = "embed-english-v3.0"
DEFAULT_RERANKER_COHERE_MODEL = "rerank-english-v3.0"
# Vector extension (pgvector, vchord, or pgvectorscale)
DEFAULT_VECTOR_EXTENSION = "pgvector" # Options: "pgvector", "vchord", "pgvectorscale"
# Vector extension (pgvector vs vchord)
DEFAULT_VECTOR_EXTENSION = "pgvector" # Options: "pgvector", "vchord"
# Text search extension (native PostgreSQL, vchord BM25, or Timescale pg_textsearch)
DEFAULT_TEXT_SEARCH_EXTENSION = "native" # Options: "native", "vchord", "pg_textsearch"
# Text search extension (native PostgreSQL vs vchord BM25)
DEFAULT_TEXT_SEARCH_EXTENSION = "native" # Options: "native", "vchord"
# LiteLLM defaults
DEFAULT_LITELLM_API_BASE = "http://localhost:4000"
DEFAULT_EMBEDDINGS_LITELLM_MODEL = "text-embedding-3-small"
DEFAULT_RERANKER_LITELLM_MODEL = "cohere/rerank-english-v3.0"
# LiteLLM SDK defaults
DEFAULT_EMBEDDINGS_LITELLM_SDK_MODEL = "cohere/embed-english-v3.0"
DEFAULT_RERANKER_LITELLM_SDK_MODEL = "cohere/rerank-english-v3.0"
DEFAULT_HOST = "0.0.0.0"
DEFAULT_PORT = 8888
DEFAULT_BASE_PATH = "" # Empty string = root path
@@ -397,17 +359,6 @@ DEFAULT_RETAIN_EXTRACT_CAUSAL_LINKS = True # Extract causal links between facts
DEFAULT_RETAIN_EXTRACTION_MODE = "concise" # Extraction mode: "concise", "verbose", or "custom"
RETAIN_EXTRACTION_MODES = ("concise", "verbose", "custom") # Allowed extraction modes
DEFAULT_RETAIN_CUSTOM_INSTRUCTIONS = None # Custom extraction guidelines (only used when mode="custom")
DEFAULT_RETAIN_BATCH_TOKENS = 10_000 # ~40KB of text # Max chars per sub-batch for async retain auto-splitting
DEFAULT_RETAIN_BATCH_ENABLED = False # Use LLM Batch API for fact extraction (only when async=True)
DEFAULT_RETAIN_BATCH_POLL_INTERVAL_SECONDS = 60 # Batch API polling interval in seconds
# File storage defaults
DEFAULT_FILE_STORAGE_TYPE = "native" # PostgreSQL BYTEA storage
DEFAULT_FILE_PARSER = "markitdown" # File parser to use (markitdown is the only supported parser)
DEFAULT_FILE_CONVERSION_MAX_BATCH_SIZE_MB = 100 # Max total batch size in MB (all files combined)
DEFAULT_FILE_CONVERSION_MAX_BATCH_SIZE = 10 # Max files per batch upload
DEFAULT_ENABLE_FILE_UPLOAD_API = True # Enable file upload endpoint
DEFAULT_FILE_DELETE_AFTER_RETAIN = True # Delete file bytes after retain (saves storage)
# Observations defaults (consolidated knowledge from facts)
DEFAULT_ENABLE_OBSERVATIONS = True # Observations enabled by default
@@ -531,8 +482,6 @@ class HindsightConfig:
llm_initial_backoff: float
llm_max_backoff: float
llm_timeout: float
llm_groq_service_tier: str # Groq: "on_demand", "flex", or "auto"
llm_openai_service_tier: str | None # OpenAI: None (default) or "flex" (50% cheaper)
# Vertex AI configuration
llm_vertexai_project_id: str | None
@@ -583,9 +532,6 @@ class HindsightConfig:
embeddings_litellm_api_base: str
embeddings_litellm_api_key: str | None
embeddings_litellm_model: str
embeddings_litellm_sdk_api_key: str | None
embeddings_litellm_sdk_model: str
embeddings_litellm_sdk_api_base: str | None
# Reranker
reranker_provider: str
@@ -603,9 +549,6 @@ class HindsightConfig:
reranker_litellm_api_base: str
reranker_litellm_api_key: str | None
reranker_litellm_model: str
reranker_litellm_sdk_api_key: str | None
reranker_litellm_sdk_model: str
reranker_litellm_sdk_api_base: str | None
# Server
host: str
@@ -629,27 +572,6 @@ class HindsightConfig:
retain_extract_causal_links: bool
retain_extraction_mode: str
retain_custom_instructions: str | None
retain_batch_tokens: int
retain_batch_enabled: bool
retain_batch_poll_interval_seconds: int
# File storage (static - server-level only)
file_storage_type: str # "native" (PostgreSQL) or "s3" (S3-compatible)
file_storage_s3_bucket: str | None # S3 bucket name (required for s3 storage)
file_storage_s3_region: str | None # S3 region (optional, uses SDK default)
file_storage_s3_endpoint: str | None # S3 endpoint URL (for MinIO, R2, etc.)
file_storage_s3_access_key_id: str | None # S3 access key (optional, uses env/IAM)
file_storage_s3_secret_access_key: str | None # S3 secret key (optional, uses env/IAM)
file_storage_gcs_bucket: str | None # GCS bucket name (required for gcs storage)
file_storage_gcs_service_account_key: str | None # GCS service account key JSON (optional, uses ADC)
file_storage_azure_container: str | None # Azure container name (required for azure storage)
file_storage_azure_account_name: str | None # Azure storage account name
file_storage_azure_account_key: str | None # Azure storage account key
file_parser: str # File parser to use (e.g., "markitdown")
file_conversion_max_batch_size_mb: int # Max total batch size in MB (all files combined)
file_conversion_max_batch_size: int # Max files per request
enable_file_upload_api: bool
file_delete_after_retain: bool
# Observations settings (consolidated knowledge from facts)
enable_observations: bool
@@ -707,11 +629,6 @@ class HindsightConfig:
"reranker_cohere_base_url",
# Service Account Keys
"llm_vertexai_service_account_key",
# File storage credentials
"file_storage_s3_access_key_id",
"file_storage_s3_secret_access_key",
"file_storage_gcs_service_account_key",
"file_storage_azure_account_key",
}
# CONFIGURABLE_FIELDS: Safe behavioral settings that can be customized per-tenant/bank
@@ -726,11 +643,6 @@ class HindsightConfig:
"enable_observations",
}
@property
def file_conversion_max_batch_size_bytes(self) -> int:
"""Get maximum total batch size in bytes."""
return self.file_conversion_max_batch_size_mb * 1024 * 1024
@classmethod
def get_configurable_fields(cls) -> set[str]:
"""
@@ -787,14 +699,14 @@ class HindsightConfig:
def validate(self) -> None:
"""Validate configuration values and raise errors for invalid combinations."""
# Validate vector_extension
valid_extensions = ("pgvector", "vchord", "pgvectorscale")
valid_extensions = ("pgvector", "vchord")
if self.vector_extension not in valid_extensions:
raise ValueError(
f"Invalid vector_extension: {self.vector_extension}. Must be one of: {', '.join(valid_extensions)}"
)
# Validate text_search_extension
valid_text_search = ("native", "vchord", "pg_textsearch")
valid_text_search = ("native", "vchord")
if self.text_search_extension not in valid_text_search:
raise ValueError(
f"Invalid text_search_extension: {self.text_search_extension}. Must be one of: {', '.join(valid_text_search)}"
@@ -837,8 +749,6 @@ class HindsightConfig:
llm_initial_backoff=float(os.getenv(ENV_LLM_INITIAL_BACKOFF, str(DEFAULT_LLM_INITIAL_BACKOFF))),
llm_max_backoff=float(os.getenv(ENV_LLM_MAX_BACKOFF, str(DEFAULT_LLM_MAX_BACKOFF))),
llm_timeout=float(os.getenv(ENV_LLM_TIMEOUT, str(DEFAULT_LLM_TIMEOUT))),
llm_groq_service_tier=os.getenv(ENV_LLM_GROQ_SERVICE_TIER, DEFAULT_LLM_GROQ_SERVICE_TIER),
llm_openai_service_tier=os.getenv(ENV_LLM_OPENAI_SERVICE_TIER, DEFAULT_LLM_OPENAI_SERVICE_TIER),
# Vertex AI
llm_vertexai_project_id=os.getenv(ENV_LLM_VERTEXAI_PROJECT_ID) or DEFAULT_LLM_VERTEXAI_PROJECT_ID,
llm_vertexai_region=os.getenv(ENV_LLM_VERTEXAI_REGION, DEFAULT_LLM_VERTEXAI_REGION),
@@ -937,12 +847,6 @@ class HindsightConfig:
or os.getenv(ENV_LITELLM_API_BASE, DEFAULT_LITELLM_API_BASE),
embeddings_litellm_api_key=os.getenv(ENV_EMBEDDINGS_LITELLM_API_KEY) or os.getenv(ENV_LITELLM_API_KEY),
embeddings_litellm_model=os.getenv(ENV_EMBEDDINGS_LITELLM_MODEL, DEFAULT_EMBEDDINGS_LITELLM_MODEL),
# LiteLLM SDK embeddings (direct API access)
embeddings_litellm_sdk_api_key=os.getenv(ENV_EMBEDDINGS_LITELLM_SDK_API_KEY),
embeddings_litellm_sdk_model=os.getenv(
ENV_EMBEDDINGS_LITELLM_SDK_MODEL, DEFAULT_EMBEDDINGS_LITELLM_SDK_MODEL
),
embeddings_litellm_sdk_api_base=os.getenv(ENV_EMBEDDINGS_LITELLM_SDK_API_BASE) or None,
# Reranker
reranker_provider=os.getenv(ENV_RERANKER_PROVIDER, DEFAULT_RERANKER_PROVIDER),
reranker_local_model=os.getenv(ENV_RERANKER_LOCAL_MODEL, DEFAULT_RERANKER_LOCAL_MODEL),
@@ -972,10 +876,6 @@ class HindsightConfig:
or os.getenv(ENV_LITELLM_API_BASE, DEFAULT_LITELLM_API_BASE),
reranker_litellm_api_key=os.getenv(ENV_RERANKER_LITELLM_API_KEY) or os.getenv(ENV_LITELLM_API_KEY),
reranker_litellm_model=os.getenv(ENV_RERANKER_LITELLM_MODEL, DEFAULT_RERANKER_LITELLM_MODEL),
# LiteLLM SDK reranker (direct API access)
reranker_litellm_sdk_api_key=os.getenv(ENV_RERANKER_LITELLM_SDK_API_KEY),
reranker_litellm_sdk_model=os.getenv(ENV_RERANKER_LITELLM_SDK_MODEL, DEFAULT_RERANKER_LITELLM_SDK_MODEL),
reranker_litellm_sdk_api_base=os.getenv(ENV_RERANKER_LITELLM_SDK_API_BASE) or None,
# Server
host=os.getenv(ENV_HOST, DEFAULT_HOST),
port=int(os.getenv(ENV_PORT, DEFAULT_PORT)),
@@ -1011,37 +911,6 @@ class HindsightConfig:
os.getenv(ENV_RETAIN_EXTRACTION_MODE, DEFAULT_RETAIN_EXTRACTION_MODE)
),
retain_custom_instructions=os.getenv(ENV_RETAIN_CUSTOM_INSTRUCTIONS) or DEFAULT_RETAIN_CUSTOM_INSTRUCTIONS,
retain_batch_tokens=int(os.getenv(ENV_RETAIN_BATCH_TOKENS, str(DEFAULT_RETAIN_BATCH_TOKENS))),
retain_batch_enabled=os.getenv(ENV_RETAIN_BATCH_ENABLED, str(DEFAULT_RETAIN_BATCH_ENABLED)).lower()
== "true",
retain_batch_poll_interval_seconds=int(
os.getenv(ENV_RETAIN_BATCH_POLL_INTERVAL_SECONDS, str(DEFAULT_RETAIN_BATCH_POLL_INTERVAL_SECONDS))
),
# File storage
file_storage_type=os.getenv(ENV_FILE_STORAGE_TYPE, DEFAULT_FILE_STORAGE_TYPE),
file_storage_s3_bucket=os.getenv(ENV_FILE_STORAGE_S3_BUCKET) or None,
file_storage_s3_region=os.getenv(ENV_FILE_STORAGE_S3_REGION) or None,
file_storage_s3_endpoint=os.getenv(ENV_FILE_STORAGE_S3_ENDPOINT) or None,
file_storage_s3_access_key_id=os.getenv(ENV_FILE_STORAGE_S3_ACCESS_KEY_ID) or None,
file_storage_s3_secret_access_key=os.getenv(ENV_FILE_STORAGE_S3_SECRET_ACCESS_KEY) or None,
file_storage_gcs_bucket=os.getenv(ENV_FILE_STORAGE_GCS_BUCKET) or None,
file_storage_gcs_service_account_key=os.getenv(ENV_FILE_STORAGE_GCS_SERVICE_ACCOUNT_KEY) or None,
file_storage_azure_container=os.getenv(ENV_FILE_STORAGE_AZURE_CONTAINER) or None,
file_storage_azure_account_name=os.getenv(ENV_FILE_STORAGE_AZURE_ACCOUNT_NAME) or None,
file_storage_azure_account_key=os.getenv(ENV_FILE_STORAGE_AZURE_ACCOUNT_KEY) or None,
file_parser=os.getenv(ENV_FILE_PARSER, DEFAULT_FILE_PARSER),
file_conversion_max_batch_size_mb=int(
os.getenv(ENV_FILE_CONVERSION_MAX_BATCH_SIZE_MB, str(DEFAULT_FILE_CONVERSION_MAX_BATCH_SIZE_MB))
),
file_conversion_max_batch_size=int(
os.getenv(ENV_FILE_CONVERSION_MAX_BATCH_SIZE, str(DEFAULT_FILE_CONVERSION_MAX_BATCH_SIZE))
),
enable_file_upload_api=os.getenv(ENV_ENABLE_FILE_UPLOAD_API, str(DEFAULT_ENABLE_FILE_UPLOAD_API)).lower()
== "true",
file_delete_after_retain=os.getenv(
ENV_FILE_DELETE_AFTER_RETAIN, str(DEFAULT_FILE_DELETE_AFTER_RETAIN)
).lower()
== "true",
# Observations settings (consolidated knowledge from facts)
enable_observations=os.getenv(ENV_ENABLE_OBSERVATIONS, str(DEFAULT_ENABLE_OBSERVATIONS)).lower() == "true",
consolidation_batch_size=int(
@@ -1030,9 +1030,8 @@ async def _create_observation_directly(
tokenize($3, 'llmlingua2')::bm25_catalog.bm25vector)
RETURNING id
"""
else: # native or pg_textsearch
else: # native
# Native PostgreSQL: search_vector is GENERATED ALWAYS, don't include it
# pg_textsearch: indexes operate on base columns directly, don't populate search_vector
query = f"""
INSERT INTO {fq_table("memory_units")} (
id, bank_id, text, fact_type, embedding, proof_count, source_memory_ids, history,
@@ -21,7 +21,6 @@ from ..config import (
DEFAULT_RERANKER_FLASHRANK_CACHE_DIR,
DEFAULT_RERANKER_FLASHRANK_MODEL,
DEFAULT_RERANKER_LITELLM_MODEL,
DEFAULT_RERANKER_LITELLM_SDK_MODEL,
DEFAULT_RERANKER_LOCAL_FORCE_CPU,
DEFAULT_RERANKER_LOCAL_MAX_CONCURRENT,
DEFAULT_RERANKER_LOCAL_MODEL,
@@ -33,7 +32,6 @@ from ..config import (
ENV_RERANKER_COHERE_MODEL,
ENV_RERANKER_FLASHRANK_CACHE_DIR,
ENV_RERANKER_FLASHRANK_MODEL,
ENV_RERANKER_LITELLM_SDK_API_KEY,
ENV_RERANKER_LOCAL_FORCE_CPU,
ENV_RERANKER_LOCAL_MAX_CONCURRENT,
ENV_RERANKER_LOCAL_MODEL,
@@ -830,126 +828,6 @@ class LiteLLMCrossEncoder(CrossEncoderModel):
return all_scores
class LiteLLMSDKCrossEncoder(CrossEncoderModel):
"""
LiteLLM SDK cross-encoder for direct API integration.
Supports reranking via LiteLLM SDK without requiring a proxy server.
Supported providers: Cohere, DeepInfra, Together AI, HuggingFace, Jina AI, Voyage AI, AWS Bedrock.
Example model names:
- cohere/rerank-english-v3.0
- deepinfra/Qwen3-reranker-8B
- together_ai/Salesforce/Llama-Rank-V1
- huggingface/BAAI/bge-reranker-v2-m3
"""
def __init__(
self,
api_key: str,
model: str = DEFAULT_RERANKER_LITELLM_SDK_MODEL,
api_base: str | None = None,
timeout: float = 60.0,
):
"""
Initialize LiteLLM SDK cross-encoder client.
Args:
api_key: API key for the reranking provider
model: Model name with provider prefix (e.g., "deepinfra/Qwen3-reranker-8B")
api_base: Custom base URL for API (optional)
timeout: Request timeout in seconds (default: 60.0)
"""
self.api_key = api_key
self.model = model
self.api_base = api_base
self.timeout = timeout
self._initialized = False
self._litellm = None # Will be set during initialization
@property
def provider_name(self) -> str:
return "litellm-sdk"
async def initialize(self) -> None:
"""Initialize the LiteLLM SDK client."""
if self._initialized:
return
try:
import litellm
self._litellm = litellm # Store reference
except ImportError:
raise ImportError("litellm is required for LiteLLMSDKCrossEncoder. Install it with: pip install litellm")
api_base_msg = f" at {self.api_base}" if self.api_base else ""
logger.info(f"Reranker: initializing LiteLLM SDK provider with model {self.model}{api_base_msg}")
self._initialized = True
logger.info("Reranker: LiteLLM SDK provider initialized")
async def predict(self, pairs: list[tuple[str, str]]) -> list[float]:
"""
Score query-document pairs using the LiteLLM SDK.
Args:
pairs: List of (query, document) tuples to score
Returns:
List of relevance scores
"""
if not self._initialized:
raise RuntimeError("Reranker not initialized. Call initialize() first.")
if not pairs:
return []
# Group pairs by query for efficient batching
# LiteLLM rerank expects one query with multiple documents
query_groups: dict[str, list[tuple[int, str]]] = {}
for idx, (query, text) in enumerate(pairs):
if query not in query_groups:
query_groups[query] = []
query_groups[query].append((idx, text))
all_scores = [0.0] * len(pairs)
for query, indexed_texts in query_groups.items():
texts = [text for _, text in indexed_texts]
indices = [idx for idx, _ in indexed_texts]
# Build kwargs for rerank call
rerank_kwargs = {
"model": self.model,
"query": query,
"documents": texts,
"api_key": self.api_key,
}
if self.api_base:
rerank_kwargs["api_base"] = self.api_base
response = await self._litellm.arerank(**rerank_kwargs)
# Map scores back to original positions
# Response format: RerankResponse with results list
# Each result is a TypedDict with "index" and "relevance_score"
if hasattr(response, "results") and response.results:
for result in response.results:
# Results are TypedDicts, use dict-style access
original_idx = result["index"]
score = result.get("relevance_score", result.get("score", 0.0))
all_scores[indices[original_idx]] = score
elif isinstance(response, list):
# Direct list of scores (unlikely but defensive)
for i, score in enumerate(response):
all_scores[indices[i]] = score
else:
logger.warning(f"Unexpected response format from LiteLLM rerank: {type(response)}")
return all_scores
def create_cross_encoder_from_env() -> CrossEncoderModel:
"""
Create a CrossEncoderModel instance based on configuration.
@@ -999,20 +877,9 @@ def create_cross_encoder_from_env() -> CrossEncoderModel:
api_key=config.reranker_litellm_api_key,
model=config.reranker_litellm_model,
)
elif provider == "litellm-sdk":
api_key = config.reranker_litellm_sdk_api_key
if not api_key:
raise ValueError(
f"{ENV_RERANKER_LITELLM_SDK_API_KEY} is required when {ENV_RERANKER_PROVIDER} is 'litellm-sdk'"
)
return LiteLLMSDKCrossEncoder(
api_key=api_key,
model=config.reranker_litellm_sdk_model,
api_base=config.reranker_litellm_sdk_api_base,
)
elif provider == "rrf":
return RRFPassthroughCrossEncoder()
else:
raise ValueError(
f"Unknown reranker provider: {provider}. Supported: 'local', 'tei', 'cohere', 'flashrank', 'litellm', 'litellm-sdk', 'rrf'"
f"Unknown reranker provider: {provider}. Supported: 'local', 'tei', 'cohere', 'flashrank', 'litellm', 'rrf'"
)
@@ -19,7 +19,6 @@ import httpx
from ..config import (
DEFAULT_EMBEDDINGS_COHERE_MODEL,
DEFAULT_EMBEDDINGS_LITELLM_MODEL,
DEFAULT_EMBEDDINGS_LITELLM_SDK_MODEL,
DEFAULT_EMBEDDINGS_LOCAL_FORCE_CPU,
DEFAULT_EMBEDDINGS_LOCAL_MODEL,
DEFAULT_EMBEDDINGS_LOCAL_TRUST_REMOTE_CODE,
@@ -27,7 +26,6 @@ from ..config import (
DEFAULT_EMBEDDINGS_PROVIDER,
DEFAULT_LITELLM_API_BASE,
ENV_EMBEDDINGS_COHERE_API_KEY,
ENV_EMBEDDINGS_LITELLM_SDK_API_KEY,
ENV_EMBEDDINGS_LOCAL_FORCE_CPU,
ENV_EMBEDDINGS_LOCAL_MODEL,
ENV_EMBEDDINGS_LOCAL_TRUST_REMOTE_CODE,
@@ -722,148 +720,6 @@ class LiteLLMEmbeddings(Embeddings):
return all_embeddings
class LiteLLMSDKEmbeddings(Embeddings):
"""
LiteLLM SDK embeddings for direct API integration.
Supports embeddings via LiteLLM SDK without requiring a proxy server.
Supported providers: Cohere, OpenAI, Azure OpenAI, HuggingFace, Voyage AI, Together AI, etc.
Example model names:
- cohere/embed-english-v3.0
- openai/text-embedding-3-small
- together_ai/togethercomputer/m2-bert-80M-8k-retrieval
- voyage/voyage-2
"""
def __init__(
self,
api_key: str,
model: str = DEFAULT_EMBEDDINGS_LITELLM_SDK_MODEL,
api_base: str | None = None,
batch_size: int = 100,
timeout: float = 60.0,
):
"""
Initialize LiteLLM SDK embeddings client.
Args:
api_key: API key for the embedding provider
model: Model name with provider prefix (e.g., "cohere/embed-english-v3.0")
api_base: Custom base URL for API (optional)
batch_size: Maximum batch size for embedding requests (default: 100)
timeout: Request timeout in seconds (default: 60.0)
"""
self.api_key = api_key
self.model = model
self.api_base = api_base
self.batch_size = batch_size
self.timeout = timeout
self._litellm = None # Will be set during initialization
self._dimension: int | None = None
@property
def provider_name(self) -> str:
return "litellm-sdk"
@property
def dimension(self) -> int:
if self._dimension is None:
raise RuntimeError("Embeddings not initialized. Call initialize() first.")
return self._dimension
async def initialize(self) -> None:
"""Initialize the LiteLLM SDK client and detect dimension."""
if self._litellm is not None:
return
try:
import litellm
self._litellm = litellm # Store reference
except ImportError:
raise ImportError("litellm is required for LiteLLMSDKEmbeddings. Install it with: pip install litellm")
api_base_msg = f" at {self.api_base}" if self.api_base else ""
logger.info(f"Embeddings: initializing LiteLLM SDK provider with model {self.model}{api_base_msg}")
# Do a test embedding to detect dimension
try:
# Build kwargs for embedding call
embed_kwargs = {
"model": self.model,
"input": ["test"],
"api_key": self.api_key,
}
if self.api_base:
embed_kwargs["api_base"] = self.api_base
# Use async embedding method (standard in litellm)
response = await self._litellm.aembedding(**embed_kwargs)
# Extract dimension from response
if response.data and len(response.data) > 0:
self._dimension = len(response.data[0]["embedding"])
else:
raise RuntimeError(f"Unable to detect embedding dimension for model {self.model}")
except Exception as e:
raise RuntimeError(f"Failed to initialize LiteLLM SDK embeddings: {e}")
logger.info(f"Embeddings: LiteLLM SDK provider initialized (model: {self.model}, dim: {self._dimension})")
def encode(self, texts: list[str]) -> list[list[float]]:
"""
Generate embeddings using the LiteLLM SDK.
Args:
texts: List of text strings to encode
Returns:
List of embedding vectors (one per input text)
"""
if self._litellm is None:
raise RuntimeError("Embeddings not initialized. Call initialize() first.")
if not texts:
return []
all_embeddings = []
# Process in batches
for i in range(0, len(texts), self.batch_size):
batch = texts[i : i + self.batch_size]
try:
# Build kwargs for embedding call
embed_kwargs = {
"model": self.model,
"input": batch,
"api_key": self.api_key,
}
if self.api_base:
embed_kwargs["api_base"] = self.api_base
# Use sync embedding (litellm doesn't have async in thread-safe way)
response = self._litellm.embedding(**embed_kwargs)
# Extract embeddings from response
# Sort by index to ensure correct order
batch_embeddings = sorted(response.data, key=lambda x: x.get("index", 0))
all_embeddings.extend([e["embedding"] for e in batch_embeddings])
except Exception as e:
import traceback
logger.error(
f"Error in LiteLLM embedding for batch starting at index {i}: {e}\n"
f"Traceback: {traceback.format_exc()}"
)
raise
return all_embeddings
def create_embeddings_from_env() -> Embeddings:
"""
Create an Embeddings instance based on configuration.
@@ -915,19 +771,7 @@ def create_embeddings_from_env() -> Embeddings:
api_key=config.embeddings_litellm_api_key,
model=config.embeddings_litellm_model,
)
elif provider == "litellm-sdk":
api_key = config.embeddings_litellm_sdk_api_key
if not api_key:
raise ValueError(
f"{ENV_EMBEDDINGS_LITELLM_SDK_API_KEY} is required when {ENV_EMBEDDINGS_PROVIDER} is 'litellm-sdk'"
)
return LiteLLMSDKEmbeddings(
api_key=api_key,
model=config.embeddings_litellm_sdk_model,
api_base=config.embeddings_litellm_sdk_api_base,
)
else:
raise ValueError(
f"Unknown embeddings provider: {provider}. "
f"Supported: 'local', 'tei', 'openai', 'cohere', 'litellm', 'litellm-sdk'"
f"Unknown embeddings provider: {provider}. Supported: 'local', 'tei', 'openai', 'cohere', 'litellm'"
)
@@ -48,7 +48,6 @@ class MemoryEngineInterface(ABC):
contents: list[dict[str, Any]],
*,
request_context: "RequestContext",
document_tags: list[str] | None = None,
) -> dict[str, Any]:
"""
Retain a batch of memory items.
@@ -56,9 +55,8 @@ class MemoryEngineInterface(ABC):
Args:
bank_id: The memory bank ID.
contents: List of content dicts with 'content', optional 'event_date',
'context', 'metadata', 'document_id', and per-item 'tags'.
'context', 'metadata', 'document_id'.
request_context: Request context for authentication.
document_tags: Optional tags applied to all items in the batch.
Returns:
Dict with processing results.
@@ -563,7 +561,6 @@ class MemoryEngineInterface(ABC):
contents: list[dict[str, Any]],
*,
request_context: "RequestContext",
document_tags: list[str] | None = None,
) -> dict[str, Any]:
"""
Submit a batch retain operation to run asynchronously.
@@ -572,7 +569,6 @@ class MemoryEngineInterface(ABC):
bank_id: The memory bank ID.
contents: List of content dicts to retain.
request_context: Request context for authentication.
document_tags: Optional tags applied to all items in the async batch.
Returns:
Dict with operation_id and items_count.
@@ -128,67 +128,6 @@ class LLMInterface(ABC):
"""
pass
async def supports_batch_api(self) -> bool:
"""
Check if this provider supports batch API operations.
Returns:
True if provider supports submit_batch/get_batch_status/retrieve_batch_results
"""
return False
async def submit_batch(
self,
requests: list[dict[str, Any]],
endpoint: str = "/v1/chat/completions",
completion_window: str = "24h",
) -> dict[str, Any]:
"""
Submit a batch of requests to the provider's batch API.
Args:
requests: List of request dicts in JSONL format (custom_id, method, url, body)
endpoint: API endpoint for the batch (e.g., "/v1/chat/completions")
completion_window: Completion window (e.g., "24h")
Returns:
Dict with batch metadata: {"batch_id": str, "status": str, ...}
Raises:
NotImplementedError: If provider doesn't support batch API
"""
raise NotImplementedError(f"Batch API not supported for provider: {self.provider}")
async def get_batch_status(self, batch_id: str) -> dict[str, Any]:
"""
Get the status of a batch job.
Args:
batch_id: Batch identifier returned from submit_batch
Returns:
Dict with status info: {"batch_id": str, "status": str, "completed_at": str, ...}
Raises:
NotImplementedError: If provider doesn't support batch API
"""
raise NotImplementedError(f"Batch API not supported for provider: {self.provider}")
async def retrieve_batch_results(self, batch_id: str) -> list[dict[str, Any]]:
"""
Retrieve completed batch results.
Args:
batch_id: Batch identifier returned from submit_batch
Returns:
List of result dicts (one per request, matched by custom_id)
Raises:
NotImplementedError: If provider doesn't support batch API
"""
raise NotImplementedError(f"Batch API not supported for provider: {self.provider}")
@abstractmethod
async def cleanup(self) -> None:
"""Clean up resources (close connections, etc.)."""
@@ -67,7 +67,6 @@ def create_llm_provider(
model: str,
reasoning_effort: str,
groq_service_tier: str | None = None,
openai_service_tier: str | None = None,
vertexai_project_id: str | None = None,
vertexai_region: str | None = None,
vertexai_credentials: Any = None,
@@ -81,8 +80,7 @@ def create_llm_provider(
base_url: Base URL for the API.
model: Model name.
reasoning_effort: Reasoning effort level for supported providers.
groq_service_tier: Groq service tier (for Groq provider) - "on_demand", "flex", or "auto".
openai_service_tier: OpenAI service tier (for OpenAI provider) - None (default) or "flex" (50% cheaper).
groq_service_tier: Groq service tier (for Groq provider).
vertexai_project_id: Vertex AI project ID (for VertexAI provider).
vertexai_region: Vertex AI region (for VertexAI provider).
vertexai_credentials: Vertex AI credentials object (for VertexAI provider).
@@ -158,7 +156,6 @@ def create_llm_provider(
model=model,
reasoning_effort=reasoning_effort,
groq_service_tier=groq_service_tier,
openai_service_tier=openai_service_tier,
)
else:
@@ -180,7 +177,6 @@ class LLMProvider:
model: str,
reasoning_effort: str = "low",
groq_service_tier: str | None = None,
openai_service_tier: str | None = None,
):
"""
Initialize LLM provider.
@@ -191,17 +187,15 @@ class LLMProvider:
base_url: Base URL for the API.
model: Model name.
reasoning_effort: Reasoning effort level for supported providers.
groq_service_tier: Groq service tier ("on_demand", "flex", "auto") - from config.
openai_service_tier: OpenAI service tier (None or "flex") - from config.
groq_service_tier: Groq service tier ("on_demand", "flex", "auto"). Default: None (uses Groq's default).
"""
self.provider = provider.lower()
self.api_key = api_key
self.base_url = base_url
self.model = model
self.reasoning_effort = reasoning_effort
# Service tiers from hierarchical config (not env vars)
self.groq_service_tier = groq_service_tier
self.openai_service_tier = openai_service_tier
# Default to 'auto' for best performance, users can override to 'on_demand' for free tier
self.groq_service_tier = groq_service_tier or os.getenv(ENV_LLM_GROQ_SERVICE_TIER, "auto")
# Validate provider
valid_providers = [
@@ -278,7 +272,6 @@ class LLMProvider:
model=self.model,
reasoning_effort=self.reasoning_effort,
groq_service_tier=self.groq_service_tier,
openai_service_tier=self.openai_service_tier,
vertexai_project_id=vertexai_project_id,
vertexai_region=vertexai_region,
vertexai_credentials=vertexai_credentials,
File diff suppressed because it is too large Load Diff
@@ -1,69 +0,0 @@
"""
Typed metadata models for async operations.
These dataclasses define the structure of result_metadata for different operation types.
The metadata is exposed in the API for debugging purposes and may change without notice.
"""
from dataclasses import asdict, dataclass
from typing import Any
@dataclass
class BatchRetainParentMetadata:
"""Metadata for parent batch_retain operations (when split into sub-batches)."""
items_count: int
total_tokens: int
num_sub_batches: int
is_parent: bool = True
def to_dict(self) -> dict[str, Any]:
"""Convert to dict for JSON serialization."""
return asdict(self)
@dataclass
class BatchRetainChildMetadata:
"""Metadata for child batch_retain operations (individual sub-batches)."""
items_count: int
parent_operation_id: str
sub_batch_index: int
total_sub_batches: int
def to_dict(self) -> dict[str, Any]:
"""Convert to dict for JSON serialization."""
return asdict(self)
@dataclass
class RetainMetadata:
"""Metadata for regular retain operations (non-batched, deprecated async path)."""
items_count: int
def to_dict(self) -> dict[str, Any]:
"""Convert to dict for JSON serialization."""
return asdict(self)
@dataclass
class ConsolidationMetadata:
"""Metadata for consolidation operations."""
# Currently empty, but structure for future fields
def to_dict(self) -> dict[str, Any]:
"""Convert to dict for JSON serialization."""
return asdict(self)
@dataclass
class RefreshMentalModelMetadata:
"""Metadata for mental model refresh operations."""
mental_model_id: str
def to_dict(self) -> dict[str, Any]:
"""Convert to dict for JSON serialization."""
return asdict(self)
@@ -1,60 +0,0 @@
"""File parser implementations."""
from .base import FileParser
from .markitdown import MarkitdownParser
__all__ = ["FileParser", "MarkitdownParser", "FileParserRegistry"]
class FileParserRegistry:
"""Registry for file parsers with auto-detection."""
def __init__(self):
"""Initialize empty parser registry."""
self._parsers: dict[str, FileParser] = {}
def register(self, parser: FileParser):
"""
Register a parser.
Args:
parser: FileParser instance
"""
self._parsers[parser.name()] = parser
def get_parser(
self,
name: str | None,
filename: str,
content_type: str | None = None,
) -> FileParser:
"""
Get parser by name or auto-detect.
Args:
name: Parser name (e.g., "markitdown") or None for auto-detect
filename: File name for auto-detection
content_type: MIME type (optional)
Returns:
FileParser instance
Raises:
ValueError: If no suitable parser found
"""
if name:
# Explicit parser requested
if name not in self._parsers:
raise ValueError(f"Parser '{name}' not found. Available: {list(self._parsers.keys())}")
return self._parsers[name]
# Auto-detect parser
for parser in self._parsers.values():
if parser.supports(filename, content_type):
return parser
raise ValueError(f"No parser found for {filename}. Available parsers: {list(self._parsers.keys())}")
def list_parsers(self) -> list[str]:
"""Get list of registered parser names."""
return list(self._parsers.keys())
@@ -1,49 +0,0 @@
"""Abstract base class for file parsers."""
from abc import ABC, abstractmethod
class FileParser(ABC):
"""Abstract base for file to markdown parsers."""
@abstractmethod
async def convert(self, file_data: bytes, filename: str) -> str:
"""
Parse file to markdown.
Args:
file_data: Raw file bytes
filename: Original filename (used for format detection)
Returns:
Markdown content as string
Raises:
ValueError: If file format is not supported
RuntimeError: If parsing fails
"""
pass
@abstractmethod
def supports(self, filename: str, content_type: str | None = None) -> bool:
"""
Check if parser supports this file type.
Args:
filename: File name (used for extension check)
content_type: MIME type (optional)
Returns:
True if this parser can handle the file
"""
pass
@abstractmethod
def name(self) -> str:
"""
Get parser name.
Returns:
Parser name (e.g., "markitdown")
"""
pass
@@ -1,109 +0,0 @@
"""Markitdown parser implementation."""
import asyncio
import logging
import tempfile
from pathlib import Path
from .base import FileParser
logger = logging.getLogger(__name__)
class MarkitdownParser(FileParser):
"""
Markitdown file parser.
Uses Microsoft's markitdown library to convert various file formats
to markdown including PDF, Office docs, images (via OCR), audio, HTML.
Supported formats:
- PDF (.pdf)
- Word (.docx, .doc)
- PowerPoint (.pptx, .ppt)
- Excel (.xlsx, .xls)
- Images (.jpg, .jpeg, .png) - with OCR
- HTML (.html, .htm)
- Text (.txt, .md)
- Audio (.mp3, .wav) - with transcription
"""
def __init__(self):
"""Initialize markitdown parser."""
# Lazy import to avoid requiring markitdown for all users
try:
from markitdown import MarkItDown
self._markitdown = MarkItDown()
except ImportError as e:
raise ImportError(
"markitdown package is required for file parsing. Install with: pip install markitdown"
) from e
async def convert(self, file_data: bytes, filename: str) -> str:
"""Parse file to markdown using markitdown."""
# markitdown is synchronous, so we run it in executor to avoid blocking
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, self._convert_sync, file_data, filename)
def _convert_sync(self, file_data: bytes, filename: str) -> str:
"""Synchronous parsing (runs in thread pool)."""
# Write to temp file (markitdown requires file path)
with tempfile.NamedTemporaryFile(suffix=Path(filename).suffix, delete=False) as tmp:
tmp.write(file_data)
tmp_path = tmp.name
try:
# Parse using markitdown
result = self._markitdown.convert(tmp_path)
if not result or not result.text_content:
raise RuntimeError(f"No content extracted from '{filename}'")
return result.text_content
except Exception as e:
logger.error(f"Markitdown parsing failed for {filename}: {e}")
raise RuntimeError(f"Failed to parse '{filename}': {e}") from e
finally:
# Clean up temp file
try:
Path(tmp_path).unlink()
except Exception:
pass
def supports(self, filename: str, content_type: str | None = None) -> bool:
"""Check if markitdown supports this file type."""
# Supported extensions (from markitdown docs)
supported_extensions = {
# Documents
".pdf",
".docx",
".doc",
".pptx",
".ppt",
".xlsx",
".xls",
# Images (with OCR)
".jpg",
".jpeg",
".png",
# Web
".html",
".htm",
# Text
".txt",
".md",
".csv",
# Audio (with transcription)
".mp3",
".wav",
}
ext = Path(filename).suffix.lower()
return ext in supported_extensions
def name(self) -> str:
"""Get parser name."""
return "markitdown"
@@ -16,7 +16,6 @@ Features:
"""
import asyncio
import io
import json
import logging
import os
@@ -97,9 +96,8 @@ class OpenAICompatibleLLM(LLMInterface):
if self.provider in ("openai", "groq") and not self.api_key:
raise ValueError(f"API key is required for {self.provider}")
# Service tier configuration (from config, not env vars)
self.groq_service_tier = groq_service_tier
self.openai_service_tier = kwargs.get("openai_service_tier")
# Groq service tier configuration
self.groq_service_tier = groq_service_tier or os.getenv("HINDSIGHT_API_LLM_GROQ_SERVICE_TIER", "auto")
# Get timeout config
self.timeout = timeout or float(os.getenv(ENV_LLM_TIMEOUT, str(DEFAULT_LLM_TIMEOUT)))
@@ -784,140 +782,6 @@ class OpenAICompatibleLLM(LLMInterface):
raise last_exception
raise RuntimeError("Ollama call failed after all retries")
async def supports_batch_api(self) -> bool:
"""Check if this provider supports batch API operations."""
# Only OpenAI and Groq support batch API
return self.provider in ("openai", "groq")
async def submit_batch(
self,
requests: list[dict[str, Any]],
endpoint: str = "/v1/chat/completions",
completion_window: str = "24h",
) -> dict[str, Any]:
"""
Submit a batch of requests to OpenAI/Groq Batch API.
Args:
requests: List of request dicts with custom_id, method, url, body
endpoint: API endpoint (e.g., "/v1/chat/completions")
completion_window: Completion window (e.g., "24h")
Returns:
Dict with batch metadata including batch_id
Raises:
NotImplementedError: If provider doesn't support batch API
"""
if not await self.supports_batch_api():
raise NotImplementedError(f"Batch API not supported for provider: {self.provider}")
logger.info(f"Submitting batch with {len(requests)} requests to {self.provider}")
# Format requests as JSONL
jsonl_content = "\n".join(json.dumps(req) for req in requests)
# Upload file to provider (wrap in BytesIO with filename)
file_bytes = io.BytesIO(jsonl_content.encode("utf-8"))
file_bytes.name = "batch_input.jsonl" # OpenAI SDK needs a filename
file_response = await self._client.files.create(
file=file_bytes,
purpose="batch",
)
logger.debug(f"Uploaded batch file: {file_response.id}")
# Create batch
batch_response = await self._client.batches.create(
input_file_id=file_response.id,
endpoint=endpoint,
completion_window=completion_window,
)
logger.info(f"Batch submitted: {batch_response.id}, status={batch_response.status}")
return {
"batch_id": batch_response.id,
"status": batch_response.status,
"input_file_id": file_response.id,
"created_at": batch_response.created_at,
"request_count": len(requests),
}
async def get_batch_status(self, batch_id: str) -> dict[str, Any]:
"""
Get the status of a batch job.
Args:
batch_id: Batch identifier
Returns:
Dict with status info (batch_id, status, completed_at, etc.)
"""
if not await self.supports_batch_api():
raise NotImplementedError(f"Batch API not supported for provider: {self.provider}")
batch = await self._client.batches.retrieve(batch_id)
result = {
"batch_id": batch.id,
"status": batch.status,
"created_at": batch.created_at,
"request_counts": {
"total": batch.request_counts.total if batch.request_counts else 0,
"completed": batch.request_counts.completed if batch.request_counts else 0,
"failed": batch.request_counts.failed if batch.request_counts else 0,
},
}
if batch.completed_at:
result["completed_at"] = batch.completed_at
if batch.output_file_id:
result["output_file_id"] = batch.output_file_id
if batch.error_file_id:
result["error_file_id"] = batch.error_file_id
if batch.errors:
result["errors"] = batch.errors
return result
async def retrieve_batch_results(self, batch_id: str) -> list[dict[str, Any]]:
"""
Retrieve completed batch results.
Args:
batch_id: Batch identifier
Returns:
List of result dicts (one per request, matched by custom_id)
"""
if not await self.supports_batch_api():
raise NotImplementedError(f"Batch API not supported for provider: {self.provider}")
# Get batch status
batch = await self._client.batches.retrieve(batch_id)
if batch.status != "completed":
raise ValueError(f"Batch {batch_id} is not completed yet (status: {batch.status})")
if not batch.output_file_id:
raise ValueError(f"Batch {batch_id} has no output file")
# Download results file
logger.debug(f"Downloading results for batch {batch_id} from file {batch.output_file_id}")
file_content = await self._client.files.content(batch.output_file_id)
# Parse JSONL results
results = []
for line in file_content.text.strip().split("\n"):
if line:
results.append(json.loads(line))
logger.info(f"Retrieved {len(results)} results for batch {batch_id}")
return results
async def cleanup(self) -> None:
"""Clean up resources (close OpenAI client connections)."""
if hasattr(self, "_client") and self._client:
@@ -695,91 +695,6 @@ Example: "Lost job → couldn't pay rent → moved apartment"
- Fact 2: Moved apartment, causal_relations: [{target_index: 1, relation_type: "caused_by"}]"""
def _build_extraction_prompt_and_schema(config) -> tuple[str, type]:
"""
Build extraction prompt and response schema based on config.
Returns:
Tuple of (prompt, response_schema)
"""
fact_types_instruction = "Extract ONLY 'world' and 'assistant' type facts."
extraction_mode = config.retain_extraction_mode
extract_causal_links = config.retain_extract_causal_links
# Select base prompt based on extraction mode
if extraction_mode == "custom":
if not config.retain_custom_instructions:
base_prompt = CONCISE_FACT_EXTRACTION_PROMPT
prompt = base_prompt.format(fact_types_instruction=fact_types_instruction)
else:
base_prompt = CUSTOM_FACT_EXTRACTION_PROMPT
prompt = base_prompt.format(
fact_types_instruction=fact_types_instruction,
custom_instructions=config.retain_custom_instructions,
)
elif extraction_mode == "verbose":
base_prompt = VERBOSE_FACT_EXTRACTION_PROMPT
prompt = base_prompt.format(fact_types_instruction=fact_types_instruction)
else:
base_prompt = CONCISE_FACT_EXTRACTION_PROMPT
prompt = base_prompt.format(fact_types_instruction=fact_types_instruction)
# Add causal relationships section if enabled
if extract_causal_links:
prompt = prompt + CAUSAL_RELATIONSHIPS_SECTION
response_schema = FactExtractionResponseVerbose if extraction_mode == "verbose" else FactExtractionResponse
else:
response_schema = FactExtractionResponseNoCausal
return prompt, response_schema
def _build_user_message(chunk: str, chunk_index: int, total_chunks: int, event_date: datetime, context: str) -> str:
"""Build user message for fact extraction."""
from .orchestrator import parse_datetime_flexible
sanitized_chunk = _sanitize_text(chunk)
sanitized_context = _sanitize_text(context) if context else "none"
event_date = parse_datetime_flexible(event_date)
event_date_formatted = event_date.strftime("%A, %B %d, %Y")
return f"""Extract facts from the following text chunk.
Chunk: {chunk_index + 1}/{total_chunks}
Event Date: {event_date_formatted} ({event_date.isoformat()})
Context: {sanitized_context}
Text:
{sanitized_chunk}"""
def _build_request_body(llm_config, config, prompt: str, user_message: str, response_schema: type) -> dict:
"""Build request body for LLM API call."""
request_body = {
"model": llm_config.model,
"messages": [{"role": "system", "content": prompt}, {"role": "user", "content": user_message}],
"temperature": 0.1,
}
# Add max_completion_tokens if configured
if config.retain_max_completion_tokens:
request_body["max_completion_tokens"] = config.retain_max_completion_tokens
# Add service_tier for OpenAI Flex Processing
if llm_config.provider == "openai" and llm_config._provider_impl.openai_service_tier:
request_body["service_tier"] = llm_config._provider_impl.openai_service_tier
# Add response_format (JSON schema)
if hasattr(response_schema, "model_json_schema"):
schema = response_schema.model_json_schema()
request_body["response_format"] = {
"type": "json_schema",
"json_schema": {"name": "facts", "schema": schema},
}
return request_body
async def _extract_facts_from_chunk(
chunk: str,
chunk_index: int,
@@ -802,20 +717,72 @@ async def _extract_facts_from_chunk(
logger = logging.getLogger(__name__)
# Build prompt and schema using helper function
prompt, response_schema = _build_extraction_prompt_and_schema(config)
# Determine which fact types to extract
# Note: We use "assistant" in the prompt but convert to "bank" for storage
fact_types_instruction = "Extract ONLY 'world' and 'assistant' type facts."
# Check config for extraction mode and causal link extraction
extraction_mode = config.retain_extraction_mode
extract_causal_links = config.retain_extract_causal_links
# Build user message using helper function
user_message = _build_user_message(chunk, chunk_index, total_chunks, event_date, context)
# Select base prompt based on extraction mode
if extraction_mode == "custom":
# Custom mode: inject user-provided guidelines
if not config.retain_custom_instructions:
logger.warning(
"extraction_mode='custom' but HINDSIGHT_API_RETAIN_CUSTOM_INSTRUCTIONS not set. "
"Falling back to 'concise' mode."
)
base_prompt = CONCISE_FACT_EXTRACTION_PROMPT
prompt = base_prompt.format(fact_types_instruction=fact_types_instruction)
else:
base_prompt = CUSTOM_FACT_EXTRACTION_PROMPT
prompt = base_prompt.format(
fact_types_instruction=fact_types_instruction,
custom_instructions=config.retain_custom_instructions,
)
elif extraction_mode == "verbose":
base_prompt = VERBOSE_FACT_EXTRACTION_PROMPT
prompt = base_prompt.format(fact_types_instruction=fact_types_instruction)
else:
base_prompt = CONCISE_FACT_EXTRACTION_PROMPT
prompt = base_prompt.format(fact_types_instruction=fact_types_instruction)
# Build the full prompt with or without causal relationships section
# Select appropriate response schema based on extraction mode and causal links
if extract_causal_links:
prompt = prompt + CAUSAL_RELATIONSHIPS_SECTION
if extraction_mode == "verbose":
response_schema = FactExtractionResponseVerbose
else:
response_schema = FactExtractionResponse
else:
response_schema = FactExtractionResponseNoCausal
# Retry logic for JSON validation errors
max_retries = 2
last_error = None
# Sanitize input text to prevent Unicode encoding errors (e.g., unpaired surrogates)
sanitized_chunk = _sanitize_text(chunk)
sanitized_context = _sanitize_text(context) if context else "none"
# Build user message with metadata and chunk content in a clear format
# Format event_date with day of week for better temporal reasoning
# Handle both datetime objects and ISO string formats (from deserialized async tasks)
from .orchestrator import parse_datetime_flexible
event_date = parse_datetime_flexible(event_date)
event_date_formatted = event_date.strftime("%A, %B %d, %Y") # e.g., "Monday, June 10, 2024"
user_message = f"""Extract facts from the following text chunk.
Chunk: {chunk_index + 1}/{total_chunks}
Event Date: {event_date_formatted} ({event_date.isoformat()})
Context: {sanitized_context}
Text:
{sanitized_chunk}"""
usage = TokenUsage() # Track cumulative usage across retries
for attempt in range(max_retries):
try:
@@ -1278,420 +1245,8 @@ logger = logging.getLogger(__name__)
SECONDS_PER_FACT = 10
async def extract_facts_from_contents_batch_api(
contents: list[RetainContent],
llm_config,
agent_name: str,
config,
pool=None,
operation_id: str | None = None,
schema: str | None = None,
) -> tuple[list[ExtractedFactType], list[ChunkMetadata], TokenUsage]:
"""
Extract facts using LLM Batch API (OpenAI/Groq).
Submits all chunks as a single batch, polls until complete, then processes results.
Only called when config.retain_batch_enabled=True.
Args:
contents: List of RetainContent objects to process
llm_config: LLM configuration with batch API support
agent_name: Name of the agent
config: Resolved HindsightConfig for this bank
pool: Database connection pool (for storing batch state)
operation_id: Async operation ID (for crash recovery)
schema: Database schema (for multi-tenant support)
Returns:
Tuple of (extracted_facts, chunks_metadata, usage)
"""
if not contents:
return [], [], TokenUsage()
logger.info(f"Using Batch API for fact extraction ({len(contents)} contents)")
# Check config for extraction mode and causal link extraction (used throughout)
extraction_mode = config.retain_extraction_mode
extract_causal_links = config.retain_extract_causal_links
# Check if provider supports batch API
if not await llm_config._provider_impl.supports_batch_api():
logger.warning(f"Batch API not supported for provider {llm_config.provider}, falling back to sync mode")
return await extract_facts_from_contents(contents, llm_config, agent_name, config, pool, operation_id, schema)
# Check if we're resuming an existing batch (crash recovery)
batch_id = None
if operation_id and pool:
from ..task_backend import fq_table
table = fq_table("async_operations", schema)
row = await pool.fetchrow(
f"SELECT result_metadata FROM {table} WHERE operation_id = $1",
operation_id,
)
if row and row["result_metadata"]:
metadata = row["result_metadata"]
if isinstance(metadata, str):
metadata = json.loads(metadata)
batch_id = metadata.get("batch_id")
if batch_id:
logger.info(f"Resuming existing batch: batch_id={batch_id} (crash recovery)")
# Step 1: Chunk all contents and build batch requests (skip if resuming)
all_chunks_info = [] # List of (chunk_text, content_index, chunk_index_in_content, event_date, context)
batch_requests = []
# Build prompt and schema once (same for all chunks)
prompt, response_schema = _build_extraction_prompt_and_schema(config)
for content_index, item in enumerate(contents):
chunks = chunk_text(item.content, max_chars=config.retain_chunk_size)
for chunk_index_in_content, chunk in enumerate(chunks):
all_chunks_info.append((chunk, content_index, chunk_index_in_content, item.event_date, item.context))
# Build batch request for this chunk
custom_id = f"chunk_{len(all_chunks_info) - 1}" # Global chunk index
# Build user message using helper function
user_message = _build_user_message(
chunk, chunk_index_in_content, len(chunks), item.event_date, item.context
)
# Build request body using helper function
request_body = _build_request_body(llm_config, config, prompt, user_message, response_schema)
batch_requests.append(
{"custom_id": custom_id, "method": "POST", "url": "/v1/chat/completions", "body": request_body}
)
if not batch_requests and not batch_id: # No requests and not resuming
return [], [], TokenUsage()
# Step 2: Submit batch (skip if resuming)
if not batch_id:
logger.info(f"Submitting batch with {len(batch_requests)} chunk requests")
batch_metadata = await llm_config._provider_impl.submit_batch(batch_requests)
batch_id = batch_metadata["batch_id"]
logger.info(f"Batch submitted: {batch_id}, polling every {config.retain_batch_poll_interval_seconds}s")
# CRITICAL: Store minimal batch state in operation metadata for crash recovery
# This allows resuming polling if worker restarts
if operation_id and pool:
batch_state = {
"batch_id": batch_id,
"batch_provider": llm_config.provider,
"chunk_count": len(batch_requests),
}
# Update operation result_metadata
from ..task_backend import fq_table
table = fq_table("async_operations", schema)
await pool.execute(
f"""
UPDATE {table}
SET result_metadata = result_metadata || $1::jsonb, updated_at = now()
WHERE operation_id = $2
""",
json.dumps(batch_state),
operation_id,
)
logger.info(f"Stored batch state for operation {operation_id} (crash recovery enabled)")
else:
logger.info(f"Resuming polling for existing batch: {batch_id}")
# Step 3: Poll until complete
import time
start_time = time.time()
while True:
status_info = await llm_config._provider_impl.get_batch_status(batch_id)
status = status_info["status"]
elapsed = time.time() - start_time
logger.info(
f"Batch {batch_id}: status={status}, "
f"completed={status_info['request_counts']['completed']}/{status_info['request_counts']['total']}, "
f"elapsed={elapsed:.0f}s"
)
if status == "completed":
break
elif status in ("failed", "expired", "cancelled"):
error_msg = status_info.get("errors", "Unknown error")
raise RuntimeError(f"Batch {batch_id} failed with status {status}: {error_msg}")
# Wait before polling again
await asyncio.sleep(config.retain_batch_poll_interval_seconds)
logger.info(f"Batch {batch_id} completed in {elapsed:.0f}s, retrieving results")
# Step 4: Retrieve results
batch_results = await llm_config._provider_impl.retrieve_batch_results(batch_id)
# Map results by custom_id
results_by_id = {result["custom_id"]: result for result in batch_results}
# Step 5: Parse results into facts (same as sync mode)
all_facts_from_llm = []
chunks_metadata = []
total_usage = TokenUsage()
for chunk_idx, (chunk_content, content_index, chunk_index_in_content, event_date, context) in enumerate(
all_chunks_info
):
custom_id = f"chunk_{chunk_idx}"
result = results_by_id.get(custom_id)
if not result:
logger.warning(f"Missing result for {custom_id}, skipping")
chunks_metadata.append(
ChunkMetadata(
chunk_text=chunk_content, fact_count=0, content_index=content_index, chunk_index=chunk_idx
)
)
continue
# Check for errors
if result.get("error"):
logger.error(f"Error in {custom_id}: {result['error']}")
chunks_metadata.append(
ChunkMetadata(
chunk_text=chunk_content, fact_count=0, content_index=content_index, chunk_index=chunk_idx
)
)
continue
# Extract response
response_body = result.get("response", {}).get("body", {})
choices = response_body.get("choices", [])
if not choices:
logger.warning(f"No choices in response for {custom_id}")
chunks_metadata.append(
ChunkMetadata(
chunk_text=chunk_content, fact_count=0, content_index=content_index, chunk_index=chunk_idx
)
)
continue
# Parse JSON content
message = choices[0].get("message", {})
content_str = message.get("content", "{}")
try:
extraction_response_json = json.loads(content_str)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse JSON for {custom_id}: {e}")
chunks_metadata.append(
ChunkMetadata(
chunk_text=chunk_content, fact_count=0, content_index=content_index, chunk_index=chunk_idx
)
)
continue
# Parse facts (reuse existing logic from _extract_facts_from_chunk)
raw_facts = extraction_response_json.get("facts", [])
chunk_facts = []
for i, llm_fact in enumerate(raw_facts):
if not isinstance(llm_fact, dict):
continue
def get_value(field_name):
value = llm_fact.get(field_name)
if value and value != "" and value != [] and value != {} and str(value).upper() != "N/A":
return value
return None
what = get_value("what")
if not what:
what = get_value("factual_core")
if not what:
continue
when = get_value("when")
who = get_value("who")
why = get_value("why")
# Critical field: fact_type
original_fact_type = llm_fact.get("fact_type")
fact_type = original_fact_type
# Convert "assistant" → "experience"
if fact_type == "assistant":
fact_type = "experience"
# Validate fact_type
if fact_type not in ["world", "experience", "opinion"]:
fact_kind = llm_fact.get("fact_kind")
if fact_kind == "assistant":
fact_type = "experience"
elif fact_kind in ["world", "experience", "opinion"]:
fact_type = fact_kind
else:
fact_type = "world"
# Build combined fact text
combined_parts = [what]
if when:
combined_parts.append(f"When: {when}")
if who:
combined_parts.append(f"Involving: {who}")
if why:
combined_parts.append(why)
combined_text = " | ".join(combined_parts)
# Temporal fields
fact_data = {}
fact_kind = llm_fact.get("fact_kind", "conversation")
if fact_kind not in ["conversation", "event", "other"]:
fact_kind = "conversation"
if fact_kind == "event":
occurred_start = get_value("occurred_start")
occurred_end = get_value("occurred_end")
if not occurred_start:
fact_data["occurred_start"] = _infer_temporal_date(combined_text, event_date)
else:
fact_data["occurred_start"] = occurred_start
if occurred_end:
fact_data["occurred_end"] = occurred_end
elif fact_data.get("occurred_start"):
fact_data["occurred_end"] = fact_data["occurred_start"]
# Entities
entities = get_value("entities")
if entities:
validated_entities = []
for ent in entities:
if isinstance(ent, str):
validated_entities.append(Entity(text=ent))
elif isinstance(ent, dict) and "text" in ent:
try:
validated_entities.append(Entity.model_validate(ent))
except Exception:
pass
if validated_entities:
fact_data["entities"] = validated_entities
# Causal relations
if extract_causal_links:
validated_relations = []
causal_relations_raw = get_value("causal_relations")
if causal_relations_raw:
for rel in causal_relations_raw:
if not isinstance(rel, dict):
continue
target_idx = rel.get("target_index")
relation_type = rel.get("relation_type")
strength = rel.get("strength", 1.0)
if target_idx is None or relation_type is None:
continue
if target_idx < 0 or target_idx >= i:
continue
try:
validated_relations.append(
CausalRelation(
target_fact_index=target_idx, relation_type=relation_type, strength=strength
)
)
except Exception:
pass
if validated_relations:
fact_data["causal_relations"] = validated_relations
# Always set mentioned_at
fact_data["mentioned_at"] = event_date.isoformat()
try:
fact = Fact(fact=combined_text, fact_type=fact_type, **fact_data)
chunk_facts.append(fact)
except Exception as e:
logger.error(f"Failed to create Fact model for fact {i}: {e}")
continue
all_facts_from_llm.extend(chunk_facts)
chunks_metadata.append(
ChunkMetadata(
chunk_text=chunk_content,
fact_count=len(chunk_facts),
content_index=content_index,
chunk_index=chunk_idx,
)
)
# Track token usage
usage_data = response_body.get("usage", {})
if usage_data:
total_usage = total_usage + TokenUsage(
input_tokens=usage_data.get("prompt_tokens", 0),
output_tokens=usage_data.get("completion_tokens", 0),
total_tokens=usage_data.get("total_tokens", 0),
)
# Step 6: Convert to ExtractedFact objects with proper chunk mapping
# Group facts by chunk
facts_by_chunk = [] # List of (chunk_metadata, [facts])
fact_start_idx = 0
for chunk_meta in chunks_metadata:
chunk_facts = all_facts_from_llm[fact_start_idx : fact_start_idx + chunk_meta.fact_count]
facts_by_chunk.append((chunk_meta, chunk_facts))
fact_start_idx += chunk_meta.fact_count
# Now convert to ExtractedFactType
extracted_facts = []
global_fact_idx = 0
for chunk_meta, chunk_facts in facts_by_chunk:
content = contents[chunk_meta.content_index]
for fact_from_llm in chunk_facts:
extracted_fact = ExtractedFactType(
fact_text=fact_from_llm.fact,
fact_type=fact_from_llm.fact_type,
entities=[e.text for e in (fact_from_llm.entities or [])],
occurred_start=_parse_datetime(fact_from_llm.occurred_start) if fact_from_llm.occurred_start else None,
occurred_end=_parse_datetime(fact_from_llm.occurred_end) if fact_from_llm.occurred_end else None,
causal_relations=_convert_causal_relations(fact_from_llm.causal_relations or [], global_fact_idx),
content_index=chunk_meta.content_index,
chunk_index=chunk_meta.chunk_index,
context=content.context,
mentioned_at=content.event_date,
metadata=content.metadata,
tags=content.tags,
)
extracted_facts.append(extracted_fact)
global_fact_idx += 1
# Step 7: Add temporal offsets
_add_temporal_offsets(extracted_facts, contents)
logger.info(f"Batch API extracted {len(extracted_facts)} facts from {len(all_chunks_info)} chunks")
return extracted_facts, chunks_metadata, total_usage
async def extract_facts_from_contents(
contents: list[RetainContent],
llm_config,
agent_name: str,
config,
pool=None,
operation_id: str | None = None,
schema: str | None = None,
contents: list[RetainContent], llm_config, agent_name: str, config
) -> tuple[list[ExtractedFactType], list[ChunkMetadata], TokenUsage]:
"""
Extract facts from multiple content items in parallel.
@@ -1702,16 +1257,11 @@ async def extract_facts_from_contents(
3. Adds time offsets to preserve fact ordering within each content
4. Returns typed ExtractedFact and ChunkMetadata objects
Routes to batch API mode if config.retain_batch_enabled=True.
Args:
contents: List of RetainContent objects to process
llm_config: LLM configuration for fact extraction
agent_name: Name of the agent (for agent-related fact detection)
config: Resolved HindsightConfig for this bank
pool: Database connection pool (passed to batch API for state storage)
operation_id: Async operation ID (passed to batch API for crash recovery)
schema: Database schema (passed to batch API for multi-tenant support)
Returns:
Tuple of (extracted_facts, chunks_metadata, usage)
@@ -1719,12 +1269,6 @@ async def extract_facts_from_contents(
if not contents:
return [], [], TokenUsage()
# Route to batch API if enabled
if config.retain_batch_enabled:
return await extract_facts_from_contents_batch_api(
contents, llm_config, agent_name, config, pool, operation_id, schema
)
# Step 1: Create parallel fact extraction tasks
fact_extraction_tasks = []
for item in contents:
@@ -97,9 +97,8 @@ async def insert_facts_batch(
FROM input_data
RETURNING id
"""
else: # native or pg_textsearch
else: # native
# Native PostgreSQL: search_vector is GENERATED ALWAYS, don't include it
# pg_textsearch: indexes operate on base columns directly, don't populate search_vector
query = f"""
WITH input_data AS (
SELECT * FROM unnest(
@@ -82,8 +82,6 @@ async def retain_batch(
fact_type_override: str | None = None,
confidence_score: float | None = None,
document_tags: list[str] | None = None,
operation_id: str | None = None,
schema: str | None = None,
) -> tuple[list[list[str]], TokenUsage]:
"""
Process a batch of content through the retain pipeline.
@@ -149,7 +147,7 @@ async def retain_batch(
step_start = time.time()
extracted_facts, chunks, usage = await fact_extraction.extract_facts_from_contents(
contents, llm_config, agent_name, config, pool, operation_id, schema
contents, llm_config, agent_name, config
)
log_buffer.append(
f"[1] Extract facts: {len(extracted_facts)} facts, {len(chunks)} chunks from {len(contents)} contents in {time.time() - step_start:.3f}s"
@@ -164,74 +164,99 @@ async def retrieve_semantic_bm25_combined(
# Build tags clause - param 6 if tags provided
tags_clause = build_tags_where_clause_simple(tags, 6, match=tags_match)
# Build backend-specific BM25 parts
if config.text_search_extension == "vchord":
# VectorChord BM25: use <&> operator with to_bm25query and tokenize
# Note: VectorChord scores are negative (higher = better, so -1 > -10)
bm25_score_expr = "search_vector <&> to_bm25query('idx_memory_units_text_search', tokenize($5, 'llmlingua2'))"
bm25_order_by = f"{bm25_score_expr} DESC"
bm25_where_filter = "" # No additional WHERE filter for vchord
params = [query_emb_str, bank_id, fact_types, limit, query_text] # Pass raw query_text for tokenization
elif config.text_search_extension == "pg_textsearch":
# Timescale pg_textsearch: use <@> operator with to_bm25query
# Note: pg_textsearch scores are negative (lower/more negative = better, so -10 > -1)
# We negate the score to maintain API consistency (higher = better)
bm25_score_expr = "-(text <@> to_bm25query($5, 'idx_memory_units_text_search'))"
bm25_order_by = "text <@> to_bm25query($5, 'idx_memory_units_text_search') ASC"
bm25_where_filter = "" # No additional WHERE filter for pg_textsearch
params = [query_emb_str, bank_id, fact_types, limit, query_text]
if tags:
params.append(tags)
query = f"""
WITH semantic_ranked AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
1 - (embedding <=> $1::vector) AS similarity,
NULL::float AS bm25_score,
'semantic' AS source,
ROW_NUMBER() OVER (PARTITION BY fact_type ORDER BY embedding <=> $1::vector) AS rn
FROM {fq_table("memory_units")}
WHERE bank_id = $2
AND embedding IS NOT NULL
AND fact_type = ANY($3)
AND (1 - (embedding <=> $1::vector)) >= 0.3
{tags_clause}
),
bm25_ranked AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
NULL::float AS similarity,
search_vector <&> to_bm25query('idx_memory_units_text_search', tokenize($5, 'llmlingua2')) AS bm25_score,
'bm25' AS source,
ROW_NUMBER() OVER (PARTITION BY fact_type ORDER BY search_vector <&> to_bm25query('idx_memory_units_text_search', tokenize($5, 'llmlingua2')) DESC) AS rn
FROM {fq_table("memory_units")}
WHERE bank_id = $2
AND fact_type = ANY($3)
{tags_clause}
),
semantic AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
similarity, bm25_score, source
FROM semantic_ranked WHERE rn <= $4
),
bm25 AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
similarity, bm25_score, source
FROM bm25_ranked WHERE rn <= $4
)
SELECT * FROM semantic
UNION ALL
SELECT * FROM bm25
"""
else: # native
# Native PostgreSQL: use ts_rank_cd with to_tsquery
query_tsquery = " | ".join(tokens)
bm25_score_expr = "ts_rank_cd(search_vector, to_tsquery('english', $5))"
bm25_order_by = f"{bm25_score_expr} DESC"
bm25_where_filter = "AND search_vector @@ to_tsquery('english', $5)"
params = [query_emb_str, bank_id, fact_types, limit, query_tsquery]
if tags:
params.append(tags)
if tags:
params.append(tags)
# Single query template with backend-specific parts injected
query = f"""
WITH semantic_ranked AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
1 - (embedding <=> $1::vector) AS similarity,
NULL::float AS bm25_score,
'semantic' AS source,
ROW_NUMBER() OVER (PARTITION BY fact_type ORDER BY embedding <=> $1::vector) AS rn
FROM {fq_table("memory_units")}
WHERE bank_id = $2
AND embedding IS NOT NULL
AND fact_type = ANY($3)
AND (1 - (embedding <=> $1::vector)) >= 0.3
{tags_clause}
),
bm25_ranked AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
NULL::float AS similarity,
{bm25_score_expr} AS bm25_score,
'bm25' AS source,
ROW_NUMBER() OVER (PARTITION BY fact_type ORDER BY {bm25_order_by}) AS rn
FROM {fq_table("memory_units")}
WHERE bank_id = $2
AND fact_type = ANY($3)
{bm25_where_filter}
{tags_clause}
),
semantic AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
similarity, bm25_score, source
FROM semantic_ranked WHERE rn <= $4
),
bm25 AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
similarity, bm25_score, source
FROM bm25_ranked WHERE rn <= $4
)
SELECT * FROM semantic
UNION ALL
SELECT * FROM bm25
"""
query = f"""
WITH semantic_ranked AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
1 - (embedding <=> $1::vector) AS similarity,
NULL::float AS bm25_score,
'semantic' AS source,
ROW_NUMBER() OVER (PARTITION BY fact_type ORDER BY embedding <=> $1::vector) AS rn
FROM {fq_table("memory_units")}
WHERE bank_id = $2
AND embedding IS NOT NULL
AND fact_type = ANY($3)
AND (1 - (embedding <=> $1::vector)) >= 0.3
{tags_clause}
),
bm25_ranked AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
NULL::float AS similarity,
ts_rank_cd(search_vector, to_tsquery('english', $5)) AS bm25_score,
'bm25' AS source,
ROW_NUMBER() OVER (PARTITION BY fact_type ORDER BY ts_rank_cd(search_vector, to_tsquery('english', $5)) DESC) AS rn
FROM {fq_table("memory_units")}
WHERE bank_id = $2
AND fact_type = ANY($3)
AND search_vector @@ to_tsquery('english', $5)
{tags_clause}
),
semantic AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
similarity, bm25_score, source
FROM semantic_ranked WHERE rn <= $4
),
bm25 AS (
SELECT id, text, context, event_date, occurred_start, occurred_end, mentioned_at, embedding, fact_type, document_id, chunk_id, tags,
similarity, bm25_score, source
FROM bm25_ranked WHERE rn <= $4
)
SELECT * FROM semantic
UNION ALL
SELECT * FROM bm25
"""
# Combined CTE query for both semantic and BM25 across all fact types
# Uses window functions to limit per fact_type per method
@@ -1,77 +0,0 @@
"""File storage backends for uploaded files."""
from collections.abc import Callable
from .base import FileStorage
from .postgresql import PostgreSQLFileStorage
__all__ = ["FileStorage", "PostgreSQLFileStorage", "create_file_storage"]
def create_file_storage(
storage_type: str,
pool_getter: Callable | None = None,
schema: str | None = None,
**kwargs,
) -> FileStorage:
"""
Create file storage backend based on configuration.
Args:
storage_type: "native" (PostgreSQL BYTEA) or "s3" (S3-compatible object storage)
pool_getter: Database pool getter (required for native)
schema: Database schema (for native multi-tenant)
**kwargs: Additional args passed to storage backend
Returns:
FileStorage instance
Raises:
ValueError: If storage_type is unknown or required args are missing
"""
if storage_type == "native":
if not pool_getter:
raise ValueError("pool_getter required for native (PostgreSQL) storage")
return PostgreSQLFileStorage(pool_getter=pool_getter, schema=schema)
elif storage_type == "s3":
from ...config import get_config
from .s3 import S3FileStorage
config = get_config()
bucket = config.file_storage_s3_bucket
if not bucket:
raise ValueError("HINDSIGHT_API_FILE_STORAGE_S3_BUCKET is required for S3 storage")
return S3FileStorage(
bucket=bucket,
region=config.file_storage_s3_region,
endpoint=config.file_storage_s3_endpoint,
access_key_id=config.file_storage_s3_access_key_id,
secret_access_key=config.file_storage_s3_secret_access_key,
)
elif storage_type == "gcs":
from ...config import get_config
from .gcs import GCSFileStorage
config = get_config()
bucket = config.file_storage_gcs_bucket
if not bucket:
raise ValueError("HINDSIGHT_API_FILE_STORAGE_GCS_BUCKET is required for GCS storage")
return GCSFileStorage(
bucket=bucket,
service_account_key=config.file_storage_gcs_service_account_key,
)
elif storage_type == "azure":
from ...config import get_config
from .azure import AzureFileStorage
config = get_config()
container = config.file_storage_azure_container
if not container:
raise ValueError("HINDSIGHT_API_FILE_STORAGE_AZURE_CONTAINER is required for Azure storage")
return AzureFileStorage(
container_name=container,
account_name=config.file_storage_azure_account_name,
account_key=config.file_storage_azure_account_key,
)
else:
raise ValueError(f"Unknown storage type: {storage_type}. Supported: 'native', 's3', 'gcs', 'azure'.")
@@ -1,62 +0,0 @@
"""Azure Blob Storage backend using obstore."""
import logging
from datetime import timedelta
import obstore as obs
from obstore.store import AzureStore
from .base import FileStorage
logger = logging.getLogger(__name__)
class AzureFileStorage(FileStorage):
"""
Azure Blob Storage backend.
Uses obstore (Rust-backed) for high-throughput async access to Azure Blob Storage.
Supports account key, SAS token, and default Azure credentials.
"""
def __init__(
self,
container_name: str,
account_name: str | None = None,
account_key: str | None = None,
):
kwargs: dict = {}
if account_name:
kwargs["account_name"] = account_name
if account_key:
kwargs["account_key"] = account_key
self._store = AzureStore(container_name, **kwargs)
logger.info(f"Initialized Azure file storage: container={container_name}, account={account_name}")
async def store(self, file_data: bytes, key: str, metadata: dict[str, str] | None = None) -> str:
await obs.put_async(self._store, key, file_data)
logger.debug(f"Stored file {key} ({len(file_data)} bytes) in Azure")
return key
async def retrieve(self, key: str) -> bytes:
try:
response = await obs.get_async(self._store, key)
return await response.bytes_async()
except Exception as e:
if "not found" in str(e).lower() or "BlobNotFound" in str(e):
raise FileNotFoundError(f"File not found: {key}") from e
raise
async def delete(self, key: str) -> None:
await obs.delete_async(self._store, key)
async def exists(self, key: str) -> bool:
try:
await obs.head_async(self._store, key)
return True
except Exception:
return False
async def get_download_url(self, key: str, expires_in: int = 3600) -> str:
return await obs.sign_async(self._store, "GET", key, timedelta(seconds=expires_in))
@@ -1,83 +0,0 @@
"""Abstract base class for file storage backends."""
from abc import ABC, abstractmethod
class FileStorage(ABC):
"""Abstract base for file storage backends."""
@abstractmethod
async def store(
self,
file_data: bytes,
key: str,
metadata: dict[str, str] | None = None,
) -> str:
"""
Store file and return storage key.
Args:
file_data: Raw file bytes
key: Storage key (e.g., "banks/{bank_id}/files/{file_id}.pdf")
metadata: Optional metadata to store with file
Returns:
Storage key that can be used to retrieve the file
"""
pass
@abstractmethod
async def retrieve(self, key: str) -> bytes:
"""
Retrieve file by storage key.
Args:
key: Storage key
Returns:
File data as bytes
Raises:
FileNotFoundError: If file does not exist
"""
pass
@abstractmethod
async def delete(self, key: str) -> None:
"""
Delete file by storage key.
Args:
key: Storage key
"""
pass
@abstractmethod
async def exists(self, key: str) -> bool:
"""
Check if file exists.
Args:
key: Storage key
Returns:
True if file exists, False otherwise
"""
pass
@abstractmethod
async def get_download_url(self, key: str, expires_in: int = 3600) -> str:
"""
Get a URL for downloading the file.
For PostgreSQL storage, this might be a relative API path.
For S3, this would be a pre-signed URL.
Args:
key: Storage key
expires_in: Expiration time in seconds (may be ignored for some backends)
Returns:
Download URL or path
"""
pass
@@ -1,59 +0,0 @@
"""Google Cloud Storage backend using obstore."""
import logging
from datetime import timedelta
import obstore as obs
from obstore.store import GCSStore
from .base import FileStorage
logger = logging.getLogger(__name__)
class GCSFileStorage(FileStorage):
"""
Google Cloud Storage backend.
Uses obstore (Rust-backed) for high-throughput async access to GCS.
Supports Application Default Credentials, service account keys, and explicit credentials.
"""
def __init__(
self,
bucket: str,
service_account_key: str | None = None,
):
kwargs: dict = {}
if service_account_key:
kwargs["service_account_key"] = service_account_key
self._store = GCSStore(bucket, **kwargs)
logger.info(f"Initialized GCS file storage: bucket={bucket}")
async def store(self, file_data: bytes, key: str, metadata: dict[str, str] | None = None) -> str:
await obs.put_async(self._store, key, file_data)
logger.debug(f"Stored file {key} ({len(file_data)} bytes) in GCS")
return key
async def retrieve(self, key: str) -> bytes:
try:
response = await obs.get_async(self._store, key)
return await response.bytes_async()
except Exception as e:
if "not found" in str(e).lower():
raise FileNotFoundError(f"File not found: {key}") from e
raise
async def delete(self, key: str) -> None:
await obs.delete_async(self._store, key)
async def exists(self, key: str) -> bool:
try:
await obs.head_async(self._store, key)
return True
except Exception:
return False
async def get_download_url(self, key: str, expires_in: int = 3600) -> str:
return await obs.sign_async(self._store, "GET", key, timedelta(seconds=expires_in))
@@ -1,139 +0,0 @@
"""PostgreSQL BYTEA-based file storage (default, zero-config)."""
import logging
from collections.abc import Callable
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import asyncpg
from .base import FileStorage
logger = logging.getLogger(__name__)
def fq_table(table: str, schema: str | None = None) -> str:
"""Get fully-qualified table name with optional schema prefix."""
if schema:
return f'"{schema}".{table}'
return table
class PostgreSQLFileStorage(FileStorage):
"""
PostgreSQL BYTEA-based file storage.
Stores files directly in PostgreSQL using BYTEA columns.
This is the default storage backend - zero configuration required!
Pros:
- Works out of the box (no external dependencies)
- Transactional consistency with database
- Simple backups (included in pg_dump)
- Good performance for <10MB files
Cons:
- Database bloat for large/many files
- Not ideal for distributed deployments
- Higher cost than object storage at scale
For production/scale, consider S3FileStorage instead.
"""
def __init__(self, pool_getter: Callable[[], "asyncpg.Pool"], schema: str | None = None):
"""
Initialize PostgreSQL file storage.
Args:
pool_getter: Function that returns asyncpg connection pool
schema: Database schema (for multi-tenant support)
"""
self._pool_getter = pool_getter
self._schema = schema
async def store(
self,
file_data: bytes,
key: str,
metadata: dict[str, str] | None = None,
) -> str:
"""Store file in PostgreSQL."""
pool = self._pool_getter()
async with pool.acquire() as conn:
await conn.execute(
f"""
INSERT INTO {fq_table("file_storage", self._schema)}
(storage_key, data)
VALUES ($1, $2)
ON CONFLICT (storage_key) DO UPDATE SET
data = EXCLUDED.data
""",
key,
file_data,
)
logger.debug(f"Stored file {key} ({len(file_data)} bytes) in PostgreSQL")
return key
async def retrieve(self, key: str) -> bytes:
"""Retrieve file from PostgreSQL."""
pool = self._pool_getter()
async with pool.acquire() as conn:
row = await conn.fetchrow(
f"""
SELECT data FROM {fq_table("file_storage", self._schema)}
WHERE storage_key = $1
""",
key,
)
if not row:
raise FileNotFoundError(f"File not found: {key}")
return bytes(row["data"])
async def delete(self, key: str) -> None:
"""Delete file from PostgreSQL."""
pool = self._pool_getter()
async with pool.acquire() as conn:
result = await conn.execute(
f"""
DELETE FROM {fq_table("file_storage", self._schema)}
WHERE storage_key = $1
""",
key,
)
# Check if anything was deleted
if result == "DELETE 0":
logger.warning(f"Attempted to delete non-existent file: {key}")
async def exists(self, key: str) -> bool:
"""Check if file exists in PostgreSQL."""
pool = self._pool_getter()
async with pool.acquire() as conn:
row = await conn.fetchrow(
f"""
SELECT 1 FROM {fq_table("file_storage", self._schema)}
WHERE storage_key = $1
""",
key,
)
return row is not None
async def get_download_url(self, key: str, expires_in: int = 3600) -> str:
"""
Get download URL for PostgreSQL-stored file.
Returns an API endpoint path (not a pre-signed URL since the file
is stored in the database). The expires_in parameter is ignored
for PostgreSQL storage.
"""
# Return API path for download endpoint
# (expires_in ignored for database storage - auth handled at API level)
return f"/v1/default/files/download/{key}"
@@ -1,71 +0,0 @@
"""S3 object storage backend using obstore."""
import logging
from datetime import timedelta
import obstore as obs
from obstore.store import S3Store
from .base import FileStorage
logger = logging.getLogger(__name__)
class S3FileStorage(FileStorage):
"""
S3-compatible object storage backend.
Uses obstore (Rust-backed) for high-throughput async access to
Amazon S3, MinIO, Cloudflare R2, and other S3-compliant APIs.
"""
def __init__(
self,
bucket: str,
region: str | None = None,
endpoint: str | None = None,
access_key_id: str | None = None,
secret_access_key: str | None = None,
):
kwargs: dict = {}
if region:
kwargs["region"] = region
if endpoint:
kwargs["endpoint"] = endpoint
# Allow plain HTTP for local S3-compatible services (MinIO, LocalStack, etc.)
if endpoint.startswith("http://"):
kwargs["allow_http"] = True
if access_key_id:
kwargs["access_key_id"] = access_key_id
if secret_access_key:
kwargs["secret_access_key"] = secret_access_key
self._store = S3Store(bucket, **kwargs)
logger.info(f"Initialized S3 file storage: bucket={bucket}, region={region}, endpoint={endpoint}")
async def store(self, file_data: bytes, key: str, metadata: dict[str, str] | None = None) -> str:
await obs.put_async(self._store, key, file_data)
logger.debug(f"Stored file {key} ({len(file_data)} bytes) in S3")
return key
async def retrieve(self, key: str) -> bytes:
try:
response = await obs.get_async(self._store, key)
return await response.bytes_async()
except Exception as e:
if "not found" in str(e).lower() or "NoSuchKey" in str(e):
raise FileNotFoundError(f"File not found: {key}") from e
raise
async def delete(self, key: str) -> None:
await obs.delete_async(self._store, key)
async def exists(self, key: str) -> bool:
try:
await obs.head_async(self._store, key)
return True
except Exception:
return False
async def get_download_url(self, key: str, expires_in: int = 3600) -> str:
return await obs.sign_async(self._store, "GET", key, timedelta(seconds=expires_in))
-30
View File
@@ -166,8 +166,6 @@ def main():
llm_initial_backoff=config.llm_initial_backoff,
llm_max_backoff=config.llm_max_backoff,
llm_timeout=config.llm_timeout,
llm_groq_service_tier=config.llm_groq_service_tier,
llm_openai_service_tier=config.llm_openai_service_tier,
llm_vertexai_project_id=config.llm_vertexai_project_id,
llm_vertexai_region=config.llm_vertexai_region,
llm_vertexai_service_account_key=config.llm_vertexai_service_account_key,
@@ -210,9 +208,6 @@ def main():
embeddings_litellm_api_base=config.embeddings_litellm_api_base,
embeddings_litellm_api_key=config.embeddings_litellm_api_key,
embeddings_litellm_model=config.embeddings_litellm_model,
embeddings_litellm_sdk_api_key=config.embeddings_litellm_sdk_api_key,
embeddings_litellm_sdk_model=config.embeddings_litellm_sdk_model,
embeddings_litellm_sdk_api_base=config.embeddings_litellm_sdk_api_base,
reranker_provider=config.reranker_provider,
reranker_local_model=config.reranker_local_model,
reranker_local_force_cpu=config.reranker_local_force_cpu,
@@ -228,9 +223,6 @@ def main():
reranker_litellm_api_base=config.reranker_litellm_api_base,
reranker_litellm_api_key=config.reranker_litellm_api_key,
reranker_litellm_model=config.reranker_litellm_model,
reranker_litellm_sdk_api_key=config.reranker_litellm_sdk_api_key,
reranker_litellm_sdk_model=config.reranker_litellm_sdk_model,
reranker_litellm_sdk_api_base=config.reranker_litellm_sdk_api_base,
host=args.host,
port=args.port,
base_path=config.base_path,
@@ -247,25 +239,6 @@ def main():
retain_extract_causal_links=config.retain_extract_causal_links,
retain_extraction_mode=config.retain_extraction_mode,
retain_custom_instructions=config.retain_custom_instructions,
retain_batch_tokens=config.retain_batch_tokens,
retain_batch_enabled=config.retain_batch_enabled,
retain_batch_poll_interval_seconds=config.retain_batch_poll_interval_seconds,
file_storage_type=config.file_storage_type,
file_storage_s3_bucket=config.file_storage_s3_bucket,
file_storage_s3_region=config.file_storage_s3_region,
file_storage_s3_endpoint=config.file_storage_s3_endpoint,
file_storage_s3_access_key_id=config.file_storage_s3_access_key_id,
file_storage_s3_secret_access_key=config.file_storage_s3_secret_access_key,
file_storage_gcs_bucket=config.file_storage_gcs_bucket,
file_storage_gcs_service_account_key=config.file_storage_gcs_service_account_key,
file_storage_azure_container=config.file_storage_azure_container,
file_storage_azure_account_name=config.file_storage_azure_account_name,
file_storage_azure_account_key=config.file_storage_azure_account_key,
file_parser=config.file_parser,
file_conversion_max_batch_size_mb=config.file_conversion_max_batch_size_mb,
file_conversion_max_batch_size=config.file_conversion_max_batch_size,
enable_file_upload_api=config.enable_file_upload_api,
file_delete_after_retain=config.file_delete_after_retain,
enable_observations=config.enable_observations,
consolidation_batch_size=config.consolidation_batch_size,
consolidation_max_tokens=config.consolidation_max_tokens,
@@ -367,7 +340,6 @@ def main():
"proxy_headers": args.proxy_headers,
"ws": "wsproto", # Use wsproto instead of websockets to avoid deprecation warnings
"loop": loop_impl, # Explicitly set event loop implementation
"timeout_keep_alive": 30, # Exceed aiohttp's 15s client timeout so the client always closes first
}
# Add optional parameters if provided
@@ -396,8 +368,6 @@ def main():
reranker_provider=config.reranker_provider,
mcp_enabled=config.mcp_enabled,
version=__version__,
vector_extension=config.vector_extension,
text_search_extension=config.text_search_extension,
)
# Start idle checker in daemon mode
+11 -156
View File
@@ -35,46 +35,20 @@ MIGRATION_LOCK_ID = 123456789
def _detect_vector_extension(conn, vector_extension: str = "pgvector") -> str:
"""
Validate vector extension: 'pgvector', 'vchord', or 'pgvectorscale'.
Validate vector extension: 'vchord' or 'pgvector'.
Args:
conn: SQLAlchemy connection object
vector_extension: Configured extension ("pgvector", "vchord", or "pgvectorscale")
vector_extension: Configured extension ("pgvector" or "vchord")
Returns:
"pgvector", "vchord", "pgvectorscale", or "pg_diskann"
"vchord" or "pgvector"
Raises:
RuntimeError: If configured extension is not installed
"""
# Verify the configured extension is installed
if vector_extension == "pgvectorscale":
# pgvectorscale/DiskANN requires pgvector to be installed first
pgvector_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vector'")).scalar()
if not pgvector_check:
raise RuntimeError(
"DiskANN (pgvectorscale/pg_diskann) requires pgvector to be installed. "
"Install it with: CREATE EXTENSION vector; then CREATE EXTENSION vectorscale CASCADE; (or pg_diskann on Azure)"
)
# Check for either vectorscale (open source) or pg_diskann (Azure)
vectorscale_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vectorscale'")).scalar()
pg_diskann_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'pg_diskann'")).scalar()
if vectorscale_check:
logger.debug("Using vector extension: pgvectorscale (DiskANN)")
return "pgvectorscale"
elif pg_diskann_check:
logger.debug("Using vector extension: pg_diskann (Azure DiskANN)")
return "pg_diskann" # Return distinct name for parameter handling
else:
raise RuntimeError(
"Configured vector extension 'pgvectorscale' not found. "
"Install either:\n"
" - pgvectorscale (open source): CREATE EXTENSION vectorscale CASCADE;\n"
" - pg_diskann (Azure): CREATE EXTENSION pg_diskann CASCADE;"
)
elif vector_extension == "vchord":
if vector_extension == "vchord":
vchord_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vchord'")).scalar()
if not vchord_check:
raise RuntimeError(
@@ -91,9 +65,7 @@ def _detect_vector_extension(conn, vector_extension: str = "pgvector") -> str:
logger.debug("Using configured vector extension: pgvector")
return "pgvector"
else:
raise ValueError(
f"Invalid vector_extension: {vector_extension}. Must be 'pgvector', 'vchord', or 'pgvectorscale'"
)
raise ValueError(f"Invalid vector_extension: {vector_extension}. Must be 'pgvector' or 'vchord'")
def _get_schema_lock_id(schema: str) -> int:
@@ -305,48 +277,6 @@ def run_migrations(
"Please install it with: CREATE EXTENSION vector;"
) from e
# If using pgvectorscale, ensure vectorscale extension is also installed
vector_extension = os.getenv("HINDSIGHT_API_VECTOR_EXTENSION", "pgvector").lower()
if vector_extension == "pgvectorscale":
logger.debug("Checking pgvectorscale (vectorscale) extension availability...")
vectorscale_check = conn.execute(
text("SELECT 1 FROM pg_extension WHERE extname = 'vectorscale'")
).scalar()
if vectorscale_check:
logger.info("pgvectorscale extension already installed")
else:
# Extension doesn't exist - try to install
logger.info("pgvectorscale extension not found, attempting to install...")
try:
conn.execute(text("CREATE EXTENSION vectorscale CASCADE"))
conn.commit()
logger.info("pgvectorscale extension installed successfully")
except Exception as e:
# Installation failed - check one more time in case another process installed it
conn.rollback()
vectorscale_recheck = conn.execute(
text("SELECT 1 FROM pg_extension WHERE extname = 'vectorscale'")
).fetchone()
if vectorscale_recheck:
logger.warning(
"Could not install pgvectorscale extension (permission denied?), "
"but extension exists. Continuing..."
)
else:
# Extension truly doesn't exist and we can't install it
logger.error(
f"pgvectorscale extension is not installed and cannot be installed: {e}. "
f"Please ensure pgvectorscale is installed by a database administrator. "
f"See: https://github.com/timescale/pgvectorscale#installation"
)
raise RuntimeError(
"pgvectorscale extension is required but not installed. "
"Please install it with: CREATE EXTENSION vectorscale CASCADE;"
) from e
# Run migrations while holding the lock
_run_migrations_internal(database_url, script_location, schema=schema)
finally:
@@ -545,17 +475,7 @@ def ensure_embedding_dimension(
conn.commit()
# Recreate index with appropriate type based on detected extension
if vector_ext == "pgvectorscale":
conn.execute(
text(f"""
CREATE INDEX IF NOT EXISTS idx_memory_units_embedding_diskann
ON {schema_name}.memory_units
USING diskann (embedding vector_cosine_ops)
WITH (num_neighbors = 50)
""")
)
logger.info(f"Created DiskANN index for {required_dimension}-dimensional embeddings")
elif vector_ext == "vchord":
if vector_ext == "vchord":
conn.execute(
text(f"""
CREATE INDEX IF NOT EXISTS idx_memory_units_embedding_vchordrq
@@ -617,12 +537,7 @@ def ensure_vector_extension(
]
# Determine target index type
if target_ext in ("pgvectorscale", "pg_diskann"):
target_index_type = "diskann"
elif target_ext == "vchord":
target_index_type = "vchordrq"
else:
target_index_type = "hnsw"
target_index_type = "vchordrq" if target_ext == "vchord" else "hnsw"
mismatched_tables = []
tables_with_data = []
@@ -661,9 +576,7 @@ def ensure_vector_extension(
continue
indexdef = current_index_info[0].lower()
if "diskann" in indexdef:
current_index_type = "diskann"
elif "vchordrq" in indexdef:
if "vchordrq" in indexdef:
current_index_type = "vchordrq"
elif "hnsw" in indexdef:
current_index_type = "hnsw"
@@ -696,18 +609,13 @@ def ensure_vector_extension(
# If there's data in any mismatched table, raise error
if tables_with_data:
table_list = ", ".join([f"{table}({count} rows)" for table, count in tables_with_data])
# Map index type back to extension name for error message
current_ext_name = {"diskann": "pgvectorscale", "vchordrq": "vchord", "hnsw": "pgvector"}.get(
current_index_type, current_index_type
)
raise RuntimeError(
f"Cannot change vector extension from {current_index_type} to {target_index_type}: "
f"the following tables contain data: {table_list}. "
f"To change vector extension, you must either:\n"
f" 1. Re-embed all data: DELETE FROM {schema_name}.memory_units; "
f"DELETE FROM {schema_name}.learnings; DELETE FROM {schema_name}.pinned_reflections; then restart\n"
f" 2. Use the current vector extension (set HINDSIGHT_API_VECTOR_EXTENSION='{current_ext_name}')"
f" 2. Use the current vector extension (set HINDSIGHT_API_VECTOR_EXTENSION='{current_index_type.replace('vchordrq', 'vchord').replace('hnsw', 'pgvector')}')"
)
# Tables are empty, safe to recreate indexes
@@ -720,27 +628,7 @@ def ensure_vector_extension(
conn.execute(text(f"DROP INDEX IF EXISTS {schema_name}.{index_name}"))
# Create new index with appropriate type
if target_ext == "pgvectorscale":
logger.info(f"Creating DiskANN index on {table_name} (pgvectorscale)")
conn.execute(
text(f"""
CREATE INDEX IF NOT EXISTS {index_name}
ON {schema_name}.{table_name}
USING diskann (embedding vector_cosine_ops)
WITH (num_neighbors = 50)
""")
)
elif target_ext == "pg_diskann":
logger.info(f"Creating DiskANN index on {table_name} (pg_diskann/Azure)")
conn.execute(
text(f"""
CREATE INDEX IF NOT EXISTS {index_name}
ON {schema_name}.{table_name}
USING diskann (embedding vector_cosine_ops)
WITH (max_neighbors = 50)
""")
)
elif target_ext == "vchord":
if target_ext == "vchord":
logger.info(f"Creating vchordrq index on {table_name}")
conn.execute(
text(f"""
@@ -800,9 +688,6 @@ def ensure_text_search_extension(
if text_search_extension == "vchord":
target_column_type = "bm25vector"
target_index_type = "bm25"
elif text_search_extension == "pg_textsearch":
target_column_type = "text"
target_index_type = "bm25"
else: # native
target_column_type = "tsvector"
target_index_type = "gin"
@@ -890,16 +775,7 @@ def ensure_text_search_extension(
# If there's data in any mismatched table, raise error
if tables_with_data:
table_list = ", ".join([f"{table}({count} rows)" for table, count in tables_with_data])
# Detect current extension from column type
current_col_type = mismatched_tables[0][1]
if current_col_type == "tsvector":
current_ext = "native"
elif current_col_type == "bm25vector":
current_ext = "vchord"
elif current_col_type == "text":
current_ext = "pg_textsearch"
else:
current_ext = "unknown"
current_ext = "native" if mismatched_tables[0][1] == "tsvector" else "vchord"
raise RuntimeError(
f"Cannot change text search extension from {current_ext} to {text_search_extension}: "
f"the following tables contain data: {table_list}. "
@@ -944,27 +820,6 @@ def ensure_text_search_extension(
USING bm25 (search_vector bm25_catalog.bm25_ops)
""")
)
elif text_search_extension == "pg_textsearch":
logger.info(f"Creating TEXT column on {table_name}")
# Dummy TEXT column for consistency (indexes operate on base columns)
conn.execute(text(f"ALTER TABLE {schema_name}.{table_name} ADD COLUMN search_vector TEXT"))
# Create BM25 index on expression
logger.info(f"Creating BM25 index on {table_name}")
# Different expression for each table
if table_name == "memory_units":
index_expr = "(COALESCE(text, '') || ' ' || COALESCE(context, ''))"
else: # reflections
index_expr = "(COALESCE(name, '') || ' ' || content)"
conn.execute(
text(f"""
CREATE INDEX idx_{table_name.replace(".", "_")}_text_search
ON {schema_name}.{table_name}
USING bm25({index_expr})
WITH (text_config='english')
""")
)
else: # native
logger.info(f"Creating tsvector column on {table_name}")
# Different GENERATED expression for each table
+7 -93
View File
@@ -376,12 +376,7 @@ class WorkerPoller:
del self._in_flight_by_type[operation_type]
async def _execute_task_inner(self, task: ClaimedTask):
"""Inner task execution with error handling.
Note: The executor (MemoryEngine.execute_task) handles status marking internally
(marking operations as completed/failed and handling retries). This method should
NOT override those status updates.
"""
"""Inner task execution with error handling."""
task_type = task.task_dict.get("type", "unknown")
bank_id = task.task_dict.get("bank_id", "unknown")
@@ -391,12 +386,12 @@ class WorkerPoller:
if task.schema:
task.task_dict["_schema"] = task.schema
await self._executor(task.task_dict)
logger.debug(f"Task {task.operation_id} execution finished")
await self._mark_completed(task.operation_id, task.schema)
logger.debug(f"Task {task.operation_id} completed successfully")
except Exception as e:
# The executor should handle its own errors, but if an unexpected exception
# propagates (e.g., from schema setup), log it as a warning
logger.error(f"Task {task.operation_id} raised unexpected exception: {e}")
traceback.print_exc()
error_msg = f"{type(e).__name__}: {e}\n{traceback.format_exc()}"
logger.error(f"Task {task.operation_id} failed: {e}")
await self._retry_or_fail(task.operation_id, error_msg, task.schema)
async def recover_own_tasks(self) -> int:
"""
@@ -406,8 +401,6 @@ class WorkerPoller:
On startup, we reset any tasks stuck in 'processing' for this worker_id
back to 'pending' so they can be picked up again.
Also recovers batch API operations that were in-flight.
If tenant_extension is configured, recovers across all tenant schemas.
Returns:
@@ -420,16 +413,11 @@ class WorkerPoller:
try:
table = fq_table("async_operations", schema)
# First, recover batch API operations (before resetting worker tasks)
batch_count = await self._recover_batch_operations(schema)
total_count += batch_count
# Then reset normal worker tasks
result = await self._pool.execute(
f"""
UPDATE {table}
SET status = 'pending', worker_id = NULL, claimed_at = NULL, updated_at = now()
WHERE status = 'processing' AND worker_id = $1 AND result_metadata->>'batch_id' IS NULL
WHERE status = 'processing' AND worker_id = $1
""",
self._worker_id,
)
@@ -446,80 +434,6 @@ class WorkerPoller:
logger.info(f"Worker {self._worker_id} recovered {total_count} stale tasks from previous run")
return total_count
async def _recover_batch_operations(self, schema: str | None) -> int:
"""
Recover batch API operations that were in-flight when worker crashed.
Finds operations with batch_id in metadata and re-submits them as tasks
so polling can resume.
Args:
schema: Database schema to recover from
Returns:
Number of batch operations recovered
"""
table = fq_table("async_operations", schema)
try:
# Find operations with batch_id in metadata (batch API operations)
rows = await self._pool.fetch(
f"""
SELECT operation_id, task_payload, result_metadata
FROM {table}
WHERE status = 'processing'
AND result_metadata ? 'batch_id'
AND task_payload IS NOT NULL
"""
)
if not rows:
return 0
recovered = 0
for row in rows:
operation_id = str(row["operation_id"])
task_payload = row["task_payload"]
result_metadata = row["result_metadata"]
# Parse metadata
if isinstance(result_metadata, str):
result_metadata = json.loads(result_metadata)
batch_id = result_metadata.get("batch_id")
batch_provider = result_metadata.get("batch_provider", "openai")
logger.info(
f"Recovering batch operation: operation_id={operation_id}, batch_id={batch_id}, provider={batch_provider}"
)
# Parse task_payload
if isinstance(task_payload, str):
task_dict = json.loads(task_payload)
else:
task_dict = task_payload
# Mark operation as ready for re-processing
# Reset to pending with task_payload intact so worker picks it up again
await self._pool.execute(
f"""
UPDATE {table}
SET status = 'pending', worker_id = NULL, claimed_at = NULL, updated_at = now()
WHERE operation_id = $1
""",
operation_id,
)
recovered += 1
logger.info(f"Batch operation {operation_id} reset to pending for re-processing")
return recovered
except Exception as e:
schema_display = f'"{schema}"' if schema else str(schema)
logger.error(f"Failed to recover batch operations for schema {schema_display}: {e}")
return 0
async def run(self):
"""
Main polling loop with fire-and-forget task execution.
+1 -6
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "hindsight-api"
version = "0.4.11"
version = "0.4.10"
description = "Hindsight: Agent Memory That Works Like Human Memory"
readme = "README.md"
requires-python = ">=3.11"
@@ -42,9 +42,6 @@ dependencies = [
"typer>=0.9.0",
"cohere>=5.0.0",
"flashrank>=0.2.0",
"litellm>=1.0.0",
"markitdown[pdf,docx,pptx,xlsx,xls]>=0.1.4", # File to markdown conversion
"obstore>=0.4.0", # S3/GCS/Azure object storage client (Rust-backed)
# Local ML models for embeddings/reranking - can be excluded in Docker with INCLUDE_LOCAL_MODELS=false
"sentence-transformers>=3.3.0",
"transformers>=4.53.0", # Security fixes for ReDoS vulnerabilities
@@ -67,7 +64,6 @@ test = [
"pytest-timeout>=2.4.0",
"pytest-xdist>=3.0.0",
"filelock>=3.20.1", # TOCTOU race condition fix
"testcontainers>=4.0.0",
]
[project.scripts]
@@ -117,7 +113,6 @@ dev = [
"filelock>=3.20.1", # TOCTOU race condition fix
"ruff>=0.8.0",
"ty>=0.0.1",
"testcontainers>=4.0.0",
]
[tool.ruff]
@@ -1,423 +0,0 @@
"""Test async batch retain with smart batching and parent-child operations."""
import asyncio
import json
import uuid
import pytest
from hindsight_api.extensions import RequestContext
@pytest.mark.asyncio
async def test_duplicate_document_ids_rejected_async(memory, request_context):
"""Test that async retain rejects batches with duplicate document_ids."""
bank_id = "test_duplicate_async"
contents = [
{"content": "First item", "document_id": "doc1"},
{"content": "Second item", "document_id": "doc2"},
{"content": "Third item", "document_id": "doc1"}, # Duplicate!
]
# Should raise ValueError due to duplicate document_ids
with pytest.raises(ValueError, match="duplicate document_ids.*doc1"):
await memory.submit_async_retain(
bank_id=bank_id,
contents=contents,
request_context=request_context,
)
@pytest.mark.asyncio
async def test_duplicate_document_ids_rejected_sync(memory, request_context):
"""Test that sync retain also rejects batches with duplicate document_ids."""
bank_id = "test_duplicate_sync"
contents = [
{"content": "First item", "document_id": "doc1"},
{"content": "Second item", "document_id": "doc1"}, # Duplicate!
]
# Should raise ValueError due to duplicate document_ids
with pytest.raises(ValueError, match="duplicate document_ids.*doc1"):
await memory.retain_batch_async(
bank_id=bank_id,
contents=contents,
request_context=request_context,
)
@pytest.mark.asyncio
async def test_small_async_batch_no_splitting(memory, request_context):
"""Test that small async batches create parent with single child (simplified code path)."""
bank_id = "test_small_async"
contents = [{"content": "Alice works at Google", "document_id": f"doc{i}"} for i in range(5)]
# Calculate total chars (should be well under threshold)
total_chars = sum(len(item["content"]) for item in contents)
assert total_chars < 10_000, "Test batch should be small"
# Submit async retain
result = await memory.submit_async_retain(
bank_id=bank_id,
contents=contents,
request_context=request_context,
)
# Verify we got an operation_id back
assert "operation_id" in result
assert "items_count" in result
assert result["items_count"] == 5
operation_id = result["operation_id"]
# Wait for task to complete (SyncTaskBackend executes immediately)
await asyncio.sleep(0.1)
# Check operation status
status = await memory.get_operation_status(
bank_id=bank_id,
operation_id=operation_id,
request_context=request_context,
)
# Should be a parent operation with single child (simplified code path)
assert status["status"] == "completed"
assert status["operation_type"] == "batch_retain"
assert "child_operations" in status
assert status["result_metadata"]["num_sub_batches"] == 1 # Single sub-batch
assert len(status["child_operations"]) == 1
assert status["child_operations"][0]["status"] == "completed"
@pytest.mark.asyncio
async def test_large_async_batch_auto_splits(memory, request_context):
"""Test that large async batches automatically split into sub-batches with parent operation."""
from hindsight_api.engine.memory_engine import count_tokens
bank_id = "test_large_async"
# Create a large batch that exceeds the threshold (10k tokens default)
# Repeating "A"s gets heavily compressed by tokenizer, use varied content
# Use ~22k chars per item = ~5.5k tokens per item, 2 items = ~11k tokens total (exceeds 10k)
large_content = "The quick brown fox jumps over the lazy dog. " * 500 # ~22k chars = ~5.5k tokens
contents = [{"content": large_content + f" item {i}", "document_id": f"doc{i}"} for i in range(2)]
# Calculate total tokens (should exceed threshold)
total_tokens = sum(count_tokens(item["content"]) for item in contents)
assert total_tokens > 10_000, "Test batch should exceed threshold"
# Submit async retain
result = await memory.submit_async_retain(
bank_id=bank_id,
contents=contents,
request_context=request_context,
)
# Verify we got an operation_id back
assert "operation_id" in result
assert "items_count" in result
assert result["items_count"] == 2
parent_operation_id = result["operation_id"]
# Wait for tasks to complete
await asyncio.sleep(0.5)
# Check parent operation status
parent_status = await memory.get_operation_status(
bank_id=bank_id,
operation_id=parent_operation_id,
request_context=request_context,
)
# Should be a parent operation with children
assert parent_status["operation_type"] == "batch_retain"
assert "child_operations" in parent_status
assert "num_sub_batches" in parent_status["result_metadata"]
assert parent_status["result_metadata"]["num_sub_batches"] >= 2 # Should split into at least 2 batches
assert parent_status["result_metadata"]["items_count"] == 2
# Verify child operations
child_ops = parent_status["child_operations"]
assert len(child_ops) >= 2, "Should have at least 2 child operations"
# All children should be completed (SyncTaskBackend executes immediately)
for child in child_ops:
assert child["status"] == "completed"
assert child["sub_batch_index"] is not None
assert child["items_count"] > 0
# Parent status should be aggregated as "completed"
assert parent_status["status"] == "completed"
@pytest.mark.asyncio
async def test_parent_operation_status_aggregation_pending(memory, request_context):
"""Test that parent operation shows 'pending' when children are pending."""
bank_id = "test_parent_pending"
pool = await memory._get_pool()
# Manually create a parent operation
parent_id = uuid.uuid4()
async with pool.acquire() as conn:
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status)
VALUES ($1, $2, $3, $4, $5)
""",
parent_id,
bank_id,
"batch_retain",
json.dumps({"items_count": 20, "num_sub_batches": 2, "is_parent": True}),
"pending",
)
# Create 2 child operations - one completed, one pending
child1_id = uuid.uuid4()
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status)
VALUES ($1, $2, $3, $4, $5)
""",
child1_id,
bank_id,
"retain",
json.dumps(
{
"items_count": 10,
"parent_operation_id": str(parent_id),
"sub_batch_index": 1,
"total_sub_batches": 2,
}
),
"completed",
)
child2_id = uuid.uuid4()
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status)
VALUES ($1, $2, $3, $4, $5)
""",
child2_id,
bank_id,
"retain",
json.dumps(
{
"items_count": 10,
"parent_operation_id": str(parent_id),
"sub_batch_index": 2,
"total_sub_batches": 2,
}
),
"pending",
)
# Check parent status
parent_status = await memory.get_operation_status(
bank_id=bank_id,
operation_id=str(parent_id),
request_context=request_context,
)
# Parent should aggregate as "pending" since one child is still pending
assert parent_status["status"] == "pending"
assert len(parent_status["child_operations"]) == 2
@pytest.mark.asyncio
async def test_parent_operation_status_aggregation_failed(memory, request_context):
"""Test that parent operation shows 'failed' when any child fails."""
bank_id = "test_parent_failed"
pool = await memory._get_pool()
# Manually create a parent operation
parent_id = uuid.uuid4()
async with pool.acquire() as conn:
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status)
VALUES ($1, $2, $3, $4, $5)
""",
parent_id,
bank_id,
"batch_retain",
json.dumps({"items_count": 20, "num_sub_batches": 2, "is_parent": True}),
"pending",
)
# Create 2 child operations - one completed, one failed
child1_id = uuid.uuid4()
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status)
VALUES ($1, $2, $3, $4, $5)
""",
child1_id,
bank_id,
"retain",
json.dumps(
{
"items_count": 10,
"parent_operation_id": str(parent_id),
"sub_batch_index": 1,
"total_sub_batches": 2,
}
),
"completed",
)
child2_id = uuid.uuid4()
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status, error_message)
VALUES ($1, $2, $3, $4, $5, $6)
""",
child2_id,
bank_id,
"retain",
json.dumps(
{
"items_count": 10,
"parent_operation_id": str(parent_id),
"sub_batch_index": 2,
"total_sub_batches": 2,
}
),
"failed",
"Test error",
)
# Check parent status
parent_status = await memory.get_operation_status(
bank_id=bank_id,
operation_id=str(parent_id),
request_context=request_context,
)
# Parent should aggregate as "failed" since one child failed
assert parent_status["status"] == "failed"
assert len(parent_status["child_operations"]) == 2
# Verify child with error is included
failed_child = [c for c in parent_status["child_operations"] if c["status"] == "failed"][0]
assert failed_child["error_message"] == "Test error"
@pytest.mark.asyncio
async def test_parent_operation_status_aggregation_completed(memory, request_context):
"""Test that parent operation shows 'completed' when all children are completed."""
bank_id = "test_parent_completed"
pool = await memory._get_pool()
# Manually create a parent operation
parent_id = uuid.uuid4()
async with pool.acquire() as conn:
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status)
VALUES ($1, $2, $3, $4, $5)
""",
parent_id,
bank_id,
"batch_retain",
json.dumps({"items_count": 20, "num_sub_batches": 2, "is_parent": True}),
"pending",
)
# Create 2 child operations - both completed
child1_id = uuid.uuid4()
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status)
VALUES ($1, $2, $3, $4, $5)
""",
child1_id,
bank_id,
"retain",
json.dumps(
{
"items_count": 10,
"parent_operation_id": str(parent_id),
"sub_batch_index": 1,
"total_sub_batches": 2,
}
),
"completed",
)
child2_id = uuid.uuid4()
await conn.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, result_metadata, status)
VALUES ($1, $2, $3, $4, $5)
""",
child2_id,
bank_id,
"retain",
json.dumps(
{
"items_count": 10,
"parent_operation_id": str(parent_id),
"sub_batch_index": 2,
"total_sub_batches": 2,
}
),
"completed",
)
# Check parent status
parent_status = await memory.get_operation_status(
bank_id=bank_id,
operation_id=str(parent_id),
request_context=request_context,
)
# Parent should aggregate as "completed" since all children are completed
assert parent_status["status"] == "completed"
assert len(parent_status["child_operations"]) == 2
assert all(c["status"] == "completed" for c in parent_status["child_operations"])
@pytest.mark.asyncio
async def test_config_retain_batch_tokens_respected(memory, request_context):
"""Test that the retain_batch_tokens config setting is respected."""
from hindsight_api.config import get_config
from hindsight_api.engine.memory_engine import count_tokens
bank_id = "test_config_batch_tokens"
config = get_config()
# Check that config has the retain_batch_tokens setting
assert hasattr(config, "retain_batch_tokens")
assert config.retain_batch_tokens > 0
# Create a batch that's just under the threshold
# Use content that produces roughly half the token limit per item
content_size = config.retain_batch_tokens * 2 # chars (rough estimate: 1 token ~= 4 chars)
contents = [{"content": "A" * content_size, "document_id": f"doc{i}"} for i in range(2)]
total_tokens = sum(count_tokens(item["content"]) for item in contents)
# Should be equal to threshold (boundary case, no splitting since we use > not >=)
assert total_tokens <= config.retain_batch_tokens
# Submit - should NOT split
result = await memory.submit_async_retain(
bank_id=bank_id,
contents=contents,
request_context=request_context,
)
# Wait for completion
await asyncio.sleep(0.1)
# Check status - should be a parent with single child (even for small batches)
status = await memory.get_operation_status(
bank_id=bank_id,
operation_id=result["operation_id"],
request_context=request_context,
)
# Even small batches use parent-child pattern now (simpler code path)
assert "child_operations" in status
assert status["result_metadata"]["num_sub_batches"] == 1
@@ -1,93 +0,0 @@
"""Unit tests for async retain tag propagation."""
from unittest.mock import AsyncMock, MagicMock
import pytest
from hindsight_api.engine.memory_engine import MemoryEngine
from hindsight_api.models import RequestContext
@pytest.mark.asyncio
async def test_submit_async_retain_includes_document_tags_in_task_payload():
"""submit_async_retain should include document_tags in queued task payload."""
engine = MemoryEngine.__new__(MemoryEngine)
engine._initialized = True
engine._authenticate_tenant = AsyncMock()
engine._submit_async_operation = AsyncMock(return_value={"operation_id": "op-1"})
# Mock the pool and connection for parent operation creation
mock_conn = AsyncMock()
mock_conn.execute = AsyncMock()
mock_conn.transaction = MagicMock()
mock_conn.transaction.return_value.__aenter__ = AsyncMock()
mock_conn.transaction.return_value.__aexit__ = AsyncMock()
mock_pool = AsyncMock()
mock_pool.acquire = AsyncMock(return_value=mock_conn)
mock_pool.release = AsyncMock()
engine._get_pool = AsyncMock(return_value=mock_pool)
request_context = RequestContext(tenant_id="tenant-a", api_key_id="key-a")
contents = [{"content": "Async retain payload test."}]
document_tags = ["scope:tools", "user:alice"]
result = await MemoryEngine.submit_async_retain(
engine,
bank_id="bank-1",
contents=contents,
document_tags=document_tags,
request_context=request_context,
)
# Check result structure
assert "operation_id" in result
assert "items_count" in result
assert result["items_count"] == 1
# Verify authentication was called
engine._authenticate_tenant.assert_awaited_once_with(request_context)
# Verify child operation was submitted
engine._submit_async_operation.assert_awaited_once()
# Verify child operation payload contains document_tags
kwargs = engine._submit_async_operation.await_args.kwargs
assert kwargs["bank_id"] == "bank-1"
assert kwargs["operation_type"] == "retain"
assert kwargs["task_type"] == "batch_retain"
assert kwargs["task_payload"]["contents"] == contents
assert kwargs["task_payload"]["document_tags"] == document_tags
assert kwargs["task_payload"]["_tenant_id"] == "tenant-a"
assert kwargs["task_payload"]["_api_key_id"] == "key-a"
@pytest.mark.asyncio
async def test_handle_batch_retain_forwards_document_tags_to_retain_batch_async():
"""Worker handler should forward document_tags from task payload."""
engine = MemoryEngine.__new__(MemoryEngine)
engine._initialized = True
engine.retain_batch_async = AsyncMock(return_value={"items_count": 1})
task_dict = {
"bank_id": "bank-1",
"contents": [{"content": "Forward tags test."}],
"document_tags": ["scope:client"],
"_tenant_id": "tenant-a",
"_api_key_id": "key-a",
}
await MemoryEngine._handle_batch_retain(engine, task_dict)
engine.retain_batch_async.assert_awaited_once()
kwargs = engine.retain_batch_async.await_args.kwargs
assert kwargs["bank_id"] == "bank-1"
assert kwargs["contents"] == task_dict["contents"]
assert kwargs["document_tags"] == ["scope:client"]
request_context = kwargs["request_context"]
assert request_context.internal is True
assert request_context.user_initiated is True
assert request_context.tenant_id == "tenant-a"
assert request_context.api_key_id == "key-a"
-508
View File
@@ -1,508 +0,0 @@
"""
Test OpenAI Batch API integration for retain fact extraction.
Tests cover:
- Normal batch API flow (submit, poll, complete)
- Crash recovery (resume from existing batch_id)
- Provider fallback (when batch API not supported)
- Worker recovery on restart
"""
import pytest
import asyncio
import logging
import json
import uuid
from datetime import datetime, timezone
from unittest.mock import AsyncMock, MagicMock, patch
from hindsight_api import RequestContext
from hindsight_api.engine.retain.fact_extraction import (
extract_facts_from_contents_batch_api,
extract_facts_from_contents,
RetainContent,
)
from hindsight_api.config import HindsightConfig
from hindsight_api.engine.llm_wrapper import create_llm_provider
from hindsight_api.worker.poller import WorkerPoller
logger = logging.getLogger(__name__)
@pytest.fixture
def mock_llm_config():
"""Create a mock LLM config with batch API support."""
mock = MagicMock()
mock.provider = "openai"
mock.model = "gpt-4o-mini"
mock._provider_impl = AsyncMock()
return mock
@pytest.fixture
def test_contents():
"""Create test content for fact extraction."""
return [
RetainContent(
content="Alice is a senior software engineer at TechCorp. She specializes in distributed systems.",
event_date=datetime(2024, 1, 15, tzinfo=timezone.utc),
context="team overview",
),
RetainContent(
content="Bob joined the team last month as a junior developer. He is learning React.",
event_date=datetime(2024, 1, 15, tzinfo=timezone.utc),
context="team overview",
),
]
@pytest.fixture
def hindsight_config():
"""Create test config with batch API enabled."""
config = HindsightConfig.from_env()
config.retain_batch_enabled = True
config.retain_batch_poll_interval_seconds = 1 # Fast polling for tests
config.retain_chunk_size = 4000
config.retain_extraction_mode = "concise"
config.retain_extract_causal_links = False
return config
@pytest.mark.asyncio
async def test_batch_api_normal_flow(mock_llm_config, test_contents, hindsight_config, memory, request_context):
"""Test normal batch API flow: submit, poll, complete."""
bank_id = f"test_batch_{datetime.now(timezone.utc).timestamp()}"
try:
# Mock batch API responses
batch_id = "batch_test123"
# Mock supports_batch_api
mock_llm_config._provider_impl.supports_batch_api = AsyncMock(return_value=True)
# Mock submit_batch - returns batch metadata
mock_llm_config._provider_impl.submit_batch = AsyncMock(
return_value={
"batch_id": batch_id,
"status": "validating",
"request_counts": {"total": 2, "completed": 0, "failed": 0},
}
)
# Mock get_batch_status - simulate polling sequence
status_sequence = [
{"status": "in_progress", "request_counts": {"total": 2, "completed": 1, "failed": 0}},
{"status": "completed", "request_counts": {"total": 2, "completed": 2, "failed": 0}},
]
mock_llm_config._provider_impl.get_batch_status = AsyncMock(side_effect=status_sequence)
# Mock retrieve_batch_results - returns fact extraction results
mock_results = [
{
"custom_id": "chunk_0",
"response": {
"body": {
"choices": [
{
"message": {
"content": json.dumps({
"facts": [
{
"what": "Alice is a senior software engineer at TechCorp",
"when": "present",
"where": "TechCorp",
"who": "Alice",
"why": "Professional background information",
"fact_type": "world",
"fact_kind": "conversation",
}
]
})
}
}
],
"usage": {"prompt_tokens": 100, "completion_tokens": 50, "total_tokens": 150},
}
},
},
{
"custom_id": "chunk_1",
"response": {
"body": {
"choices": [
{
"message": {
"content": json.dumps({
"facts": [
{
"what": "Bob joined the team last month as a junior developer",
"when": "last month",
"where": "team",
"who": "Bob",
"why": "New team member information",
"fact_type": "world",
"fact_kind": "conversation",
}
]
})
}
}
],
"usage": {"prompt_tokens": 100, "completion_tokens": 50, "total_tokens": 150},
}
},
},
]
mock_llm_config._provider_impl.retrieve_batch_results = AsyncMock(return_value=mock_results)
# Call batch API extraction
facts, chunks, usage = await extract_facts_from_contents_batch_api(
contents=test_contents,
llm_config=mock_llm_config,
agent_name="test_agent",
config=hindsight_config,
pool=None, # No DB pool for this test
operation_id=None,
schema=None,
)
# Verify results
assert len(facts) == 2, "Should extract 2 facts (one per chunk)"
# Facts are ExtractedFact objects with .fact_text field
assert "Alice" in facts[0].fact_text and "senior software engineer" in facts[0].fact_text
assert "Bob" in facts[1].fact_text and "junior developer" in facts[1].fact_text
# Verify chunks metadata
assert len(chunks) == 2, "Should have 2 chunks metadata"
assert chunks[0].fact_count == 1
assert chunks[1].fact_count == 1
# Verify token usage
assert usage.input_tokens == 200 # 100 per chunk
assert usage.output_tokens == 100 # 50 per chunk
assert usage.total_tokens == 300
# Verify API calls
mock_llm_config._provider_impl.submit_batch.assert_called_once()
assert mock_llm_config._provider_impl.get_batch_status.call_count == 2
mock_llm_config._provider_impl.retrieve_batch_results.assert_called_once_with(batch_id)
logger.info("✅ Normal batch API flow test passed")
finally:
# Cleanup
try:
await memory.delete_bank(bank_id, request_context=request_context)
except Exception:
pass
@pytest.mark.asyncio
async def test_batch_api_crash_recovery(mock_llm_config, test_contents, hindsight_config, memory, request_context):
"""Test crash recovery: resume polling from existing batch_id."""
bank_id = f"test_crash_{datetime.now(timezone.utc).timestamp()}"
operation_id = str(uuid.uuid4()) # Must be UUID for async_operations table
try:
# Ensure bank exists
await memory.get_bank_profile(bank_id, request_context=request_context)
# Setup: Store batch_id in async_operations table (simulates partial execution)
batch_id = "batch_recovered_456"
pool = memory._pool
schema = request_context.tenant_id
from hindsight_api.engine.task_backend import fq_table
table = fq_table("async_operations", schema)
# Create operation with batch_id already stored
await pool.execute(
f"""
INSERT INTO {table} (operation_id, operation_type, bank_id, status, result_metadata)
VALUES ($1, 'retain', $2, 'processing', $3::jsonb)
""",
operation_id,
bank_id,
json.dumps({
"batch_id": batch_id,
"batch_provider": "openai",
"chunk_count": 2,
}),
)
# Mock batch API responses for resume scenario
mock_llm_config._provider_impl.supports_batch_api = AsyncMock(return_value=True)
# Mock get_batch_status - batch already in progress
mock_llm_config._provider_impl.get_batch_status = AsyncMock(
return_value={
"status": "completed",
"request_counts": {"total": 2, "completed": 2, "failed": 0},
}
)
# Mock retrieve_batch_results
mock_results = [
{
"custom_id": "chunk_0",
"response": {
"body": {
"choices": [
{
"message": {
"content": json.dumps({
"facts": [
{
"what": "Alice is a senior software engineer",
"when": "present",
"where": "TechCorp",
"who": "Alice",
"why": "Background",
"fact_type": "world",
"fact_kind": "conversation",
}
]
})
}
}
],
"usage": {"prompt_tokens": 100, "completion_tokens": 50, "total_tokens": 150},
}
},
},
{
"custom_id": "chunk_1",
"response": {
"body": {
"choices": [
{
"message": {
"content": json.dumps({
"facts": [
{
"what": "Bob is a junior developer",
"when": "last month",
"where": "team",
"who": "Bob",
"why": "New member",
"fact_type": "world",
"fact_kind": "conversation",
}
]
})
}
}
],
"usage": {"prompt_tokens": 100, "completion_tokens": 50, "total_tokens": 150},
}
},
},
]
mock_llm_config._provider_impl.retrieve_batch_results = AsyncMock(return_value=mock_results)
# Call batch API extraction with operation_id (crash recovery scenario)
facts, chunks, usage = await extract_facts_from_contents_batch_api(
contents=test_contents,
llm_config=mock_llm_config,
agent_name="test_agent",
config=hindsight_config,
pool=pool,
operation_id=operation_id, # Provides crash recovery context
schema=schema,
)
# Verify results
assert len(facts) == 2, "Should extract 2 facts after recovery"
# CRITICAL: Verify submit_batch was NOT called (because batch_id already exists)
mock_llm_config._provider_impl.submit_batch.assert_not_called()
# Verify get_batch_status WAS called (polling resumed)
mock_llm_config._provider_impl.get_batch_status.assert_called()
# Verify retrieve_batch_results was called with the recovered batch_id
mock_llm_config._provider_impl.retrieve_batch_results.assert_called_once_with(batch_id)
logger.info("✅ Crash recovery test passed - resumed polling without re-submission")
finally:
# Cleanup
try:
await memory.delete_bank(bank_id, request_context=request_context)
except Exception:
pass
@pytest.mark.asyncio
async def test_batch_api_fallback_unsupported_provider(mock_llm_config, test_contents, hindsight_config):
"""Test fallback to sync mode when provider doesn't support batch API."""
# Mock provider that doesn't support batch API
mock_llm_config._provider_impl.supports_batch_api = AsyncMock(return_value=False)
mock_llm_config.provider = "groq" # Example of provider
# Patch the sync mode function to verify it's called
with patch(
"hindsight_api.engine.retain.fact_extraction.extract_facts_from_contents"
) as mock_sync_extract:
mock_sync_extract.return_value = ([], [], MagicMock())
# Call batch API extraction (should fallback to sync)
await extract_facts_from_contents_batch_api(
contents=test_contents,
llm_config=mock_llm_config,
agent_name="test_agent",
config=hindsight_config,
pool=None,
operation_id=None,
schema=None,
)
# Verify fallback occurred
mock_sync_extract.assert_called_once()
# Verify batch API methods were NOT called
mock_llm_config._provider_impl.submit_batch.assert_not_called()
logger.info("✅ Fallback to sync mode test passed")
@pytest.mark.asyncio
async def test_worker_batch_recovery(memory, request_context):
"""Test that WorkerPoller._recover_batch_operations finds and resets orphaned batches."""
bank_id = f"test_worker_recovery_{datetime.now(timezone.utc).timestamp()}"
operation_id = str(uuid.uuid4()) # Must be UUID for async_operations table
try:
# Ensure bank exists
await memory.get_bank_profile(bank_id, request_context=request_context)
pool = memory._pool
schema = request_context.tenant_id
from hindsight_api.engine.task_backend import fq_table
table = fq_table("async_operations", schema)
# Create orphaned batch operation (simulates worker crash during polling)
batch_id = "batch_orphaned_999"
task_payload = {
"operation_type": "retain",
"bank_id": bank_id,
"contents": [{"content": "test", "event_date": "2024-01-15T00:00:00Z"}],
}
await pool.execute(
f"""
INSERT INTO {table} (operation_id, operation_type, bank_id, status, worker_id, result_metadata, task_payload)
VALUES ($1, 'retain', $2, 'processing', 'worker_crashed', $3::jsonb, $4::jsonb)
""",
operation_id,
bank_id,
json.dumps({
"batch_id": batch_id,
"batch_provider": "openai",
"chunk_count": 1,
}),
json.dumps(task_payload),
)
# Create WorkerPoller
from hindsight_api.extensions.builtin.tenant import DefaultTenantExtension
tenant_extension = DefaultTenantExtension(config={"schema": schema} if schema else {})
poller = WorkerPoller(
pool=pool,
worker_id="test_worker_recovery",
executor=memory,
poll_interval_ms=100,
max_retries=3,
schema=schema,
tenant_extension=tenant_extension,
max_slots=5,
consolidation_max_slots=2,
)
# Run recovery
recovered_count = await poller._recover_batch_operations(schema)
# Verify recovery
assert recovered_count == 1, "Should recover 1 batch operation"
# Verify operation was reset to pending
row = await pool.fetchrow(
f"SELECT status, worker_id FROM {table} WHERE operation_id = $1",
operation_id,
)
assert row["status"] == "pending", "Operation should be reset to pending"
assert row["worker_id"] is None, "Worker ID should be cleared"
logger.info("✅ Worker batch recovery test passed")
finally:
# Cleanup
try:
await memory.delete_bank(bank_id, request_context=request_context)
except Exception:
pass
@pytest.mark.asyncio
async def test_batch_api_via_extract_facts_from_contents(
mock_llm_config, test_contents, hindsight_config, memory, request_context
):
"""Test that extract_facts_from_contents routes to batch API when enabled."""
bank_id = f"test_routing_{datetime.now(timezone.utc).timestamp()}"
try:
# Enable batch API in config
hindsight_config.retain_batch_enabled = True
# Mock batch API support
mock_llm_config._provider_impl.supports_batch_api = AsyncMock(return_value=True)
mock_llm_config._provider_impl.submit_batch = AsyncMock(
return_value={"batch_id": "batch_123", "status": "validating", "request_counts": {}}
)
mock_llm_config._provider_impl.get_batch_status = AsyncMock(
return_value={"status": "completed", "request_counts": {"total": 1, "completed": 1, "failed": 0}}
)
mock_llm_config._provider_impl.retrieve_batch_results = AsyncMock(
return_value=[
{
"custom_id": "chunk_0",
"response": {
"body": {
"choices": [
{
"message": {
"content": json.dumps({"facts": []})
}
}
],
"usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15},
}
},
}
]
)
# Call main extract_facts_from_contents (should route to batch API)
facts, chunks, usage = await extract_facts_from_contents(
contents=test_contents,
llm_config=mock_llm_config,
agent_name="test_agent",
config=hindsight_config,
pool=None,
operation_id=None,
schema=None,
)
# Verify batch API was called
mock_llm_config._provider_impl.submit_batch.assert_called_once()
logger.info("✅ Routing to batch API test passed")
finally:
# Cleanup
try:
await memory.delete_bank(bank_id, request_context=request_context)
except Exception:
pass
@@ -1,263 +0,0 @@
"""
Real integration test for OpenAI Batch API.
This test makes REAL API calls to OpenAI and measures actual timing.
It will be slow (minutes to hours) depending on OpenAI's queue.
To run:
pytest tests/test_batch_api_integration.py -v -s
To skip in CI:
Add @pytest.mark.skip at the test level
"""
import pytest
import os
import asyncio
import logging
import time
from datetime import datetime, timezone
from dotenv import load_dotenv
from hindsight_api import RequestContext
from hindsight_api.engine.retain.fact_extraction import (
extract_facts_from_contents_batch_api,
RetainContent,
)
from hindsight_api.config import HindsightConfig
from hindsight_api.engine.llm_wrapper import LLMProvider
logger = logging.getLogger(__name__)
# Load .env file for API keys
load_dotenv()
@pytest.fixture
def openai_api_key():
"""Get OpenAI API key from environment."""
# Try both current and commented keys from .env
api_key = os.getenv("HINDSIGHT_API_LLM_API_KEY")
# Check if it's an OpenAI key (starts with sk-proj- or sk-)
if not api_key or not api_key.startswith("sk-"):
# Try the OpenAI-specific env var (if set separately)
api_key = os.getenv("OPENAI_API_KEY")
if not api_key or not api_key.startswith("sk-"):
pytest.skip("OpenAI API key not found in environment. Set OPENAI_API_KEY or uncomment OpenAI config in .env")
return api_key
@pytest.fixture
def real_llm_config(openai_api_key):
"""Create real LLM config for OpenAI."""
# Create config with OpenAI settings
config = HindsightConfig.from_env()
# Use LLMProvider wrapper (which creates _provider_impl internally)
llm_config = LLMProvider(
provider="openai",
api_key=openai_api_key,
base_url="https://api.openai.com/v1",
model="gpt-4o-mini", # Fast, cheap model for testing
reasoning_effort="medium", # Required parameter
)
return llm_config
@pytest.fixture
def test_contents_real():
"""Create realistic test content for fact extraction."""
return [
RetainContent(
content="""
Alice is a senior software engineer at TechCorp, where she has been working for 5 years.
She specializes in distributed systems and microservices architecture. Alice graduated
from MIT with a degree in Computer Science in 2015. She is known for writing clean,
well-documented code and mentoring junior developers.
""",
event_date=datetime(2024, 1, 15, 10, 30, tzinfo=timezone.utc),
context="team member profile",
),
RetainContent(
content="""
Bob joined TechCorp last month as a junior developer. He is learning React and Node.js
and recently completed his first feature, which was a user authentication flow. Bob
graduated from Berkeley with a degree in Computer Science in 2023. He is enthusiastic
and asks great questions during code reviews.
""",
event_date=datetime(2024, 1, 15, 10, 30, tzinfo=timezone.utc),
context="team member profile",
),
RetainContent(
content="""
The team uses Kubernetes for container orchestration and deploys to AWS. They follow
agile methodologies with two-week sprints. Code reviews are mandatory before merging
any pull request. The team meets every morning for a 15-minute standup to discuss
progress and blockers.
""",
event_date=datetime(2024, 1, 15, 10, 30, tzinfo=timezone.utc),
context="team processes",
),
]
@pytest.fixture
def integration_config():
"""Create config for integration test."""
config = HindsightConfig.from_env()
config.retain_batch_enabled = True
config.retain_batch_poll_interval_seconds = 30 # Poll every 30 seconds (reasonable for real API)
config.retain_chunk_size = 4000
config.retain_extraction_mode = "concise"
config.retain_extract_causal_links = False
return config
@pytest.mark.skip(reason="Real API test - takes minutes and costs money. Run manually with: pytest tests/test_batch_api_integration.py::test_real_openai_batch_api -v -s")
@pytest.mark.integration # Mark as integration test
@pytest.mark.slow # Mark as slow test
@pytest.mark.asyncio
async def test_real_openai_batch_api(real_llm_config, test_contents_real, integration_config, memory, request_context):
"""
REAL integration test: Submit actual batch to OpenAI and measure timing.
WARNING: This test:
- Makes real API calls to OpenAI
- Will take minutes to hours to complete
- Costs money (though very little with gpt-4o-mini)
- Requires valid OpenAI API key
To skip this test:
pytest tests/test_batch_api_integration.py --skip-integration
"""
bank_id = f"test_real_batch_{datetime.now(timezone.utc).timestamp()}"
logger.info("=" * 80)
logger.info("STARTING REAL OPENAI BATCH API INTEGRATION TEST")
logger.info("=" * 80)
logger.info(f"Test contents: {len(test_contents_real)} items")
logger.info(f"Poll interval: {integration_config.retain_batch_poll_interval_seconds}s")
logger.info(f"Model: {real_llm_config.model}")
logger.info("This may take several minutes to hours depending on OpenAI's queue...")
logger.info("=" * 80)
try:
# Ensure bank exists
await memory.get_bank_profile(bank_id, request_context=request_context)
# Get database pool and schema for crash recovery testing
pool = memory._pool
schema = request_context.tenant_id
# Track overall timing
test_start_time = time.time()
# Call REAL batch API extraction
logger.info("\n📤 Submitting batch to OpenAI...")
facts, chunks, usage = await extract_facts_from_contents_batch_api(
contents=test_contents_real,
llm_config=real_llm_config,
agent_name="test_agent",
config=integration_config,
pool=pool,
operation_id=None, # No crash recovery for this test
schema=schema,
)
test_end_time = time.time()
total_duration = test_end_time - test_start_time
# Log results
logger.info("\n" + "=" * 80)
logger.info("✅ BATCH COMPLETED SUCCESSFULLY")
logger.info("=" * 80)
logger.info(f"Total duration: {total_duration:.1f} seconds ({total_duration/60:.1f} minutes)")
logger.info(f"Facts extracted: {len(facts)}")
logger.info(f"Chunks processed: {len(chunks)}")
logger.info(f"Token usage: {usage.input_tokens} input + {usage.output_tokens} output = {usage.total_tokens} total")
logger.info(f"Estimated cost: ${(usage.input_tokens * 0.00015 / 1000 + usage.output_tokens * 0.0006 / 1000):.4f}")
logger.info("=" * 80)
# Log sample facts
logger.info("\n📋 Sample extracted facts:")
for i, fact in enumerate(facts[:5]): # Show first 5 facts
logger.info(f"\nFact {i+1}:")
logger.info(f" Type: {fact.fact_type}")
logger.info(f" Text: {fact.fact_text[:100]}...")
logger.info(f" Entities: {fact.entities}")
# Verify results
assert len(facts) > 0, "Should extract at least some facts"
assert len(chunks) == len(test_contents_real), f"Should have {len(test_contents_real)} chunks"
assert usage.total_tokens > 0, "Should have token usage"
# Verify fact structure
for fact in facts:
assert hasattr(fact, "fact_text"), "Fact should have fact_text"
assert hasattr(fact, "fact_type"), "Fact should have fact_type"
assert fact.fact_type in ["world", "experience", "opinion"], f"Invalid fact_type: {fact.fact_type}"
logger.info("\n✅ All assertions passed!")
# Write timing report to file for later analysis
report_path = "/tmp/openai_batch_api_timing_report.txt"
with open(report_path, "w") as f:
f.write(f"OpenAI Batch API Integration Test Report\n")
f.write(f"={'=' * 60}\n\n")
f.write(f"Test Date: {datetime.now(timezone.utc).isoformat()}\n")
f.write(f"Model: {real_llm_config.model}\n")
f.write(f"Contents: {len(test_contents_real)} items\n")
f.write(f"Poll Interval: {integration_config.retain_batch_poll_interval_seconds}s\n\n")
f.write(f"Results:\n")
f.write(f" Total Duration: {total_duration:.1f}s ({total_duration/60:.1f} min)\n")
f.write(f" Facts Extracted: {len(facts)}\n")
f.write(f" Chunks Processed: {len(chunks)}\n")
f.write(f" Token Usage: {usage.total_tokens} ({usage.input_tokens} in + {usage.output_tokens} out)\n")
f.write(f" Estimated Cost: ${(usage.input_tokens * 0.00015 / 1000 + usage.output_tokens * 0.0006 / 1000):.4f}\n")
logger.info(f"\n📄 Timing report written to: {report_path}")
finally:
# Cleanup
try:
await memory.delete_bank(bank_id, request_context=request_context)
logger.info(f"\n🧹 Cleaned up test bank: {bank_id}")
except Exception as e:
logger.error(f"Failed to cleanup bank: {e}")
@pytest.mark.skip(reason="Real API test - requires Groq API key. Run manually if needed.")
@pytest.mark.integration
@pytest.mark.slow
@pytest.mark.asyncio
async def test_real_batch_supports_groq(integration_config):
"""
Test that Groq also supports batch API (if configured).
Groq has the same batch API interface as OpenAI.
"""
groq_api_key = os.getenv("HINDSIGHT_API_LLM_API_KEY")
if not groq_api_key or not groq_api_key.startswith("gsk_"):
pytest.skip("Groq API key not found in environment")
llm_config = LLMProvider(
provider="groq",
api_key=groq_api_key,
base_url="https://api.groq.com/openai/v1",
model="llama-3.1-8b-instant",
reasoning_effort="medium",
)
# Check if Groq supports batch API
supports_batch = await llm_config._provider_impl.supports_batch_api()
logger.info(f"Groq batch API support: {supports_batch}")
# Groq should support batch API (same interface as OpenAI)
assert supports_batch, "Groq should support batch API"
logger.info("✅ Groq batch API support confirmed")
@@ -1,38 +0,0 @@
"""
Test validation for batch API + synchronous retain.
When HINDSIGHT_API_RETAIN_BATCH_ENABLED=true, synchronous retain operations
should be rejected with a 400 error since they will timeout.
"""
import os
import pytest
from hindsight_api.engine.memory_engine import MemoryEngine
from hindsight_api.config import HindsightConfig
from hindsight_api import RequestContext
@pytest.mark.asyncio
async def test_batch_api_validation(memory, request_context):
"""
Test that attempting synchronous retain with batch API enabled
raises an error at the HTTP layer.
This test verifies the validation logic exists - actual HTTP testing
would require full FastAPI app setup.
"""
# Create config with batch API enabled
config = HindsightConfig.from_env()
config.retain_batch_enabled = True
config.retain_batch_poll_interval_seconds = 1
# Verify the validation exists in memory engine
# The actual HTTP validation happens in http.py api_retain()
# This test documents the expected behavior
assert config.retain_batch_enabled is True
assert config.retain_batch_poll_interval_seconds == 1
# When batch API is enabled and async=false, the HTTP endpoint
# should return 400 with message:
# "Batch API is enabled (HINDSIGHT_API_RETAIN_BATCH_ENABLED=true) but async=false"
@@ -135,179 +135,3 @@ async def test_memory_without_document(memory, request_context):
finally:
await memory.delete_bank(bank_id, request_context=request_context)
@pytest.mark.asyncio
async def test_document_persisted_with_zero_facts(memory, request_context):
"""
Test that documents are persisted even when zero facts are extracted.
This is a regression test for issue #324 where documents with no extractable
facts were reported as disappearing from the system.
"""
bank_id = f"test_zero_facts_{datetime.now(timezone.utc).timestamp()}"
try:
document_id = "doc-zero-facts"
# Retain content that produces zero facts (gibberish/random characters)
units = await memory.retain_async(
bank_id=bank_id,
content="xyzabc123 !!!### @@@ $$$", # Random characters unlikely to produce facts
context="Test zero facts",
document_id=document_id,
request_context=request_context,
)
# Should return empty unit list (no facts extracted)
assert len(units) == 0, "Should extract zero facts from gibberish content"
# But document should still be persisted and retrievable
doc = await memory.get_document(document_id, bank_id, request_context=request_context)
assert doc is not None, "Document should be persisted even with zero facts"
assert doc["id"] == document_id
assert doc["bank_id"] == bank_id
assert doc["memory_unit_count"] == 0, "Should have zero memory units"
assert len(doc["original_text"]) > 0, "Should have non-zero text length"
assert "xyzabc123" in doc["original_text"], "Should contain original content"
# Document should also appear in list
docs_list = await memory.list_documents(
bank_id=bank_id,
search_query=None,
limit=100,
offset=0,
request_context=request_context,
)
assert docs_list["total"] == 1, "Document should appear in list"
assert any(d["id"] == document_id for d in docs_list["items"]), "Document should be in items"
listed_doc = next(d for d in docs_list["items"] if d["id"] == document_id)
assert listed_doc["memory_unit_count"] == 0, "Listed document should show zero memory units"
finally:
await memory.delete_bank(bank_id, request_context=request_context)
@pytest.mark.asyncio
async def test_document_persisted_with_zero_facts_batch(memory, request_context):
"""
Test that documents are persisted with zero facts in batch retain operations.
This tests the async batch code path to ensure it also handles zero facts correctly.
"""
bank_id = f"test_zero_facts_batch_{datetime.now(timezone.utc).timestamp()}"
try:
# Mix of content: some produces facts, some produces zero facts
contents = [
{
"content": "Alice works at Google",
"document_id": "doc-with-facts",
},
{
"content": "!@# $$$ %%% ^^^ &&& ***", # Gibberish - zero facts expected
"document_id": "doc-zero-facts",
},
]
unit_ids = await memory.retain_batch_async(
bank_id=bank_id,
contents=contents,
request_context=request_context,
)
# First content should produce facts, second should not
assert len(unit_ids[0]) > 0, "First content should produce facts"
assert len(unit_ids[1]) == 0, "Second content should produce zero facts"
# Both documents should be persisted
doc_with_facts = await memory.get_document("doc-with-facts", bank_id, request_context=request_context)
assert doc_with_facts is not None
assert doc_with_facts["memory_unit_count"] > 0
doc_zero_facts = await memory.get_document("doc-zero-facts", bank_id, request_context=request_context)
assert doc_zero_facts is not None, "Document with zero facts should be persisted"
assert doc_zero_facts["memory_unit_count"] == 0, "Should have zero memory units"
assert "!@#" in doc_zero_facts["original_text"]
# Both should appear in list
docs_list = await memory.list_documents(
bank_id=bank_id,
search_query=None,
limit=100,
offset=0,
request_context=request_context,
)
assert docs_list["total"] == 2, "Both documents should appear in list"
finally:
await memory.delete_bank(bank_id, request_context=request_context)
@pytest.mark.asyncio
async def test_document_persisted_with_zero_facts_async_submit(memory, request_context):
"""
Test that documents are persisted with zero facts in fire-and-forget async retain.
This tests the submit_async_retain (background task) code path to ensure it also
handles zero facts correctly.
"""
import asyncio
bank_id = f"test_zero_facts_async_{datetime.now(timezone.utc).timestamp()}"
try:
# Submit async retain with gibberish content
result = await memory.submit_async_retain(
bank_id=bank_id,
contents=[
{
"content": "!@# $$$ %%% ^^^ &&& ***", # Gibberish - zero facts expected
"document_id": "doc-async-zero-facts",
}
],
request_context=request_context,
)
operation_id = result["operation_id"]
assert operation_id is not None, "Should return operation_id"
# Wait for background task to complete
max_wait = 60 # 60 seconds max
wait_interval = 0.5
elapsed = 0
while elapsed < max_wait:
await asyncio.sleep(wait_interval)
elapsed += wait_interval
# Check if document exists
doc = await memory.get_document(
"doc-async-zero-facts", bank_id, request_context=request_context
)
if doc is not None:
break
# Document should be persisted even with zero facts
assert doc is not None, "Document should be persisted after async task completes"
assert doc["id"] == "doc-async-zero-facts"
assert doc["memory_unit_count"] == 0, "Should have zero memory units"
assert "!@#" in doc["original_text"]
# Document should appear in list
docs_list = await memory.list_documents(
bank_id=bank_id,
search_query=None,
limit=100,
offset=0,
request_context=request_context,
)
assert docs_list["total"] == 1, "Document should appear in list"
assert any(d["id"] == "doc-async-zero-facts" for d in docs_list["items"])
listed_doc = next(d for d in docs_list["items"] if d["id"] == "doc-async-zero-facts")
assert listed_doc["memory_unit_count"] == 0, "Listed document should show zero memory units"
finally:
await memory.delete_bank(bank_id, request_context=request_context)
-553
View File
@@ -1,553 +0,0 @@
"""
End-to-end tests for file retain (upload, convert, retain) functionality.
"""
import io
import json
import pytest
from httpx import ASGITransport, AsyncClient
@pytest.fixture
def sample_pdf_content():
"""Create a simple PDF-like content for testing."""
# This is a minimal PDF that markitdown can parse
return b"""%PDF-1.4
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [3 0 R]
/Count 1
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/MediaBox [0 0 612 792]
/Contents 4 0 R
/Resources <<
/Font <<
/F1 <<
/Type /Font
/Subtype /Type1
/BaseFont /Helvetica
>>
>>
>>
>>
endobj
4 0 obj
<<
/Length 44
>>
stream
BT
/F1 12 Tf
100 700 Td
(Test Document) Tj
ET
endstream
endobj
xref
0 5
0000000000 65535 f
0000000009 00000 n
0000000058 00000 n
0000000115 00000 n
0000000317 00000 n
trailer
<<
/Size 5
/Root 1 0 R
>>
startxref
410
%%EOF
"""
@pytest.fixture
def sample_txt_content():
"""Create simple text content."""
return b"This is a test document.\nIt contains some important information.\nAlice works at Google."
@pytest.mark.asyncio
async def test_file_retain_basic(memory_no_llm_verify, sample_txt_content):
"""Test basic file upload and conversion."""
from hindsight_api.api.http import create_app
app = create_app(memory_no_llm_verify, initialize_memory=False)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
# Create a bank first
bank_response = await client.put("/v1/default/banks/test-file-bank", json={"name": "Test File Bank"})
assert bank_response.status_code in (200, 201)
# Upload file
request_data = {
"document_tags": ["test"],
"async": True,
}
files = {"files": ("test.txt", sample_txt_content, "text/plain")}
data = {"request": json.dumps(request_data)}
response = await client.post(
"/v1/default/banks/test-file-bank/files/retain",
files=files,
data=data,
)
assert response.status_code == 200
result = response.json()
assert "operation_ids" in result
assert len(result["operation_ids"]) == 1
@pytest.mark.asyncio
async def test_file_retain_with_metadata(memory_no_llm_verify, sample_txt_content):
"""Test file upload with per-file metadata."""
from hindsight_api.api.http import create_app
app = create_app(memory_no_llm_verify, initialize_memory=False)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
# Create bank
bank_response = await client.put("/v1/default/banks/test-file-meta-bank", json={"name": "Test Meta Bank"})
assert bank_response.status_code in (200, 201)
# Upload file with metadata
request_data = {
"document_tags": ["work", "reports"],
"async": True,
"files_metadata": [
{
"document_id": "test_doc_123",
"context": "quarterly report",
"metadata": {"author": "Alice", "year": "2024"},
"tags": ["Q1"],
}
],
}
files = {"files": ("report.txt", sample_txt_content, "text/plain")}
data = {"request": json.dumps(request_data)}
response = await client.post(
"/v1/default/banks/test-file-meta-bank/files/retain",
files=files,
data=data,
)
assert response.status_code == 200
result = response.json()
assert "operation_ids" in result
assert len(result["operation_ids"]) == 1
@pytest.mark.asyncio
async def test_file_retain_multiple_files(memory_no_llm_verify, sample_txt_content):
"""Test uploading multiple files at once."""
from hindsight_api.api.http import create_app
app = create_app(memory_no_llm_verify, initialize_memory=False)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
# Create bank
bank_response = await client.put("/v1/default/banks/test-multi-file-bank", json={"name": "Test Multi Bank"})
assert bank_response.status_code in (200, 201)
# Upload multiple files
request_data = {
"async": True,
"files_metadata": [
{"document_id": "doc1", "tags": ["file1"]},
{"document_id": "doc2", "tags": ["file2"]},
],
}
content1 = b"First document content"
content2 = b"Second document content"
files = [
("files", ("file1.txt", content1, "text/plain")),
("files", ("file2.txt", content2, "text/plain")),
]
data = {"request": json.dumps(request_data)}
response = await client.post(
"/v1/default/banks/test-multi-file-bank/files/retain",
files=files,
data=data,
)
assert response.status_code == 200
result = response.json()
assert "operation_ids" in result
assert len(result["operation_ids"]) == 2
@pytest.mark.asyncio
async def test_file_retain_validation_errors(memory_no_llm_verify):
"""Test validation errors."""
from hindsight_api.api.http import create_app
app = create_app(memory_no_llm_verify, initialize_memory=False)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
# Create bank
bank_response = await client.put("/v1/default/banks/test-validation-bank", json={"name": "Test Validation Bank"})
assert bank_response.status_code in (200, 201)
# Test: metadata count mismatch
request_data = {
"async": True,
"files_metadata": [
{"document_id": "doc1"},
{"document_id": "doc2"}, # 2 metadata entries
],
}
files = {"files": ("file1.txt", b"content", "text/plain")} # But only 1 file
data = {"request": json.dumps(request_data)}
response = await client.post(
"/v1/default/banks/test-validation-bank/files/retain",
files=files,
data=data,
)
assert response.status_code == 400
assert "files_metadata count" in response.json()["detail"]
@pytest.mark.asyncio
async def test_file_retain_no_files(memory_no_llm_verify):
"""Test error when no files provided."""
from hindsight_api.api.http import create_app
app = create_app(memory_no_llm_verify, initialize_memory=False)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
# Create bank
bank_response = await client.put("/v1/default/banks/test-no-files-bank", json={"name": "Test No Files Bank"})
assert bank_response.status_code in (200, 201)
request_data = {
"async": True,
}
# No files provided
data = {"request": json.dumps(request_data)}
response = await client.post(
"/v1/default/banks/test-no-files-bank/files/retain",
data=data,
)
# FastAPI will return 422 for missing required field
assert response.status_code == 422
@pytest.mark.asyncio
async def test_file_retain_sync_not_supported(memory_no_llm_verify, sample_txt_content):
"""Test that file retain is always async (sync is not supported)."""
from hindsight_api.api.http import create_app
app = create_app(memory_no_llm_verify, initialize_memory=False)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
# Create bank
bank_response = await client.put("/v1/default/banks/test-sync-bank", json={"name": "Test Sync Bank"})
assert bank_response.status_code in (200, 201)
# File retain is always async - just verify it succeeds and returns operation_ids
files = {"files": ("test.txt", sample_txt_content, "text/plain")}
data = {"request": json.dumps({})}
response = await client.post(
"/v1/default/banks/test-sync-bank/files/retain",
files=files,
data=data,
)
assert response.status_code == 200
result = response.json()
assert "operation_ids" in result
@pytest.mark.asyncio
async def test_file_storage_postgresql(memory_no_llm_verify, sample_txt_content):
"""Test file storage in PostgreSQL."""
# Test that files are stored and retrieved correctly
storage = memory_no_llm_verify._file_storage
# Store a file
key = "test/file1.txt"
stored_key = await storage.store(
file_data=sample_txt_content,
key=key,
metadata={"content_type": "text/plain"},
)
assert stored_key == key
# Retrieve the file
retrieved = await storage.retrieve(key)
assert retrieved == sample_txt_content
# Check if file exists
exists = await storage.exists(key)
assert exists is True
# Delete the file
await storage.delete(key)
# Check file no longer exists
exists_after = await storage.exists(key)
assert exists_after is False
@pytest.mark.asyncio
async def test_markitdown_converter():
"""Test markitdown parser."""
from hindsight_api.engine.parsers import MarkitdownParser
parser = MarkitdownParser()
# Test simple text file
text_content = b"This is a test document.\nWith multiple lines."
result = await parser.convert(text_content, "test.txt")
assert isinstance(result, str)
assert len(result) > 0
assert "test document" in result.lower() or "multiple lines" in result.lower()
@pytest.mark.asyncio
async def test_converter_registry():
"""Test file parser registry."""
from hindsight_api.engine.parsers import FileParserRegistry, MarkitdownParser
registry = FileParserRegistry()
parser = MarkitdownParser()
registry.register(parser)
# Test get by name
retrieved = registry.get_parser("markitdown", "test.txt")
assert retrieved is parser
# Test auto-detection
auto = registry.get_parser(None, "test.pdf")
assert auto is parser
# Test unsupported format
with pytest.raises(ValueError, match="No parser found"):
registry.get_parser(None, "test.xyz")
@pytest.mark.asyncio
async def test_file_conversion_creates_separate_retain_operation(memory_no_llm_verify, sample_txt_content):
"""Test that file conversion and retain are two separate async operations.
The file_convert_retain task should:
1. Convert the file to markdown
2. In a single transaction: create a separate 'retain' operation AND mark itself as 'completed'
3. Free the worker slot immediately after conversion
The retain then runs as its own task. This prevents deadlocks where file conversion
tasks hold worker slots while waiting for inline retain to finish.
"""
from hindsight_api.models import RequestContext
bank_id = "test_file_two_phase_bank"
context = RequestContext(internal=True)
await memory_no_llm_verify.get_bank_profile(bank_id, request_context=context)
class MockFile:
def __init__(self, content, filename, content_type):
self.content = content
self.filename = filename
self.content_type = content_type
async def read(self):
return self.content
mock_file = MockFile(sample_txt_content, "test.txt", "text/plain")
file_items = [
{
"file": mock_file,
"document_id": "test_doc_two_phase",
"context": "test context",
"metadata": {"source": "test"},
"tags": ["test_tag"],
"timestamp": None,
}
]
result = await memory_no_llm_verify.submit_async_file_retain(
bank_id=bank_id,
file_items=file_items,
parser="markitdown",
document_tags=["two_phase_test"],
request_context=context,
)
assert "operation_ids" in result
assert len(result["operation_ids"]) == 1
convert_operation_id = result["operation_ids"][0]
import asyncio
await asyncio.sleep(0.1)
pool = await memory_no_llm_verify._get_pool()
from hindsight_api.engine.memory_engine import get_current_schema
schema = get_current_schema()
async with pool.acquire() as conn:
# 1. The file_convert_retain operation must be completed
convert_op = await conn.fetchrow(
f"SELECT status, operation_type FROM {schema}.async_operations WHERE operation_id = $1",
convert_operation_id,
)
assert convert_op is not None
assert convert_op["operation_type"] == "file_convert_retain"
assert convert_op["status"] == "completed", (
f"file_convert_retain should be 'completed' after conversion, got '{convert_op['status']}'"
)
# 2. A separate retain operation must have been created
retain_op = await conn.fetchrow(
f"""
SELECT status, operation_type
FROM {schema}.async_operations
WHERE bank_id = $1 AND operation_type = 'retain' AND operation_id != $2
""",
bank_id,
convert_operation_id,
)
assert retain_op is not None, "A separate 'retain' operation should have been created by file conversion"
# With SyncTaskBackend the retain runs immediately, so it should be completed
assert retain_op["status"] == "completed"
# 3. The document should exist with file metadata and retained content
doc = await conn.fetchrow(
f"""
SELECT id, original_text, file_original_name, file_content_type
FROM {schema}.documents
WHERE id = $1 AND bank_id = $2
""",
"test_doc_two_phase",
bank_id,
)
assert doc is not None
assert doc["file_original_name"] == "test.txt"
assert doc["file_content_type"] == "text/plain"
assert doc["original_text"] is not None
assert len(doc["original_text"]) > 0
@pytest.mark.asyncio
async def test_file_conversion_failure_sets_status_to_failed(memory_no_llm_verify, sample_txt_content):
"""Test that when file conversion fails, the operation status is set to 'failed' not 'completed'."""
from hindsight_api.engine.parsers.base import FileParser
from hindsight_api.models import RequestContext
bank_id = "test_file_failure_bank"
# Create a mock parser that always fails
class FailingParser(FileParser):
"""Mock parser that raises an error."""
async def convert(self, file_data: bytes, filename: str) -> str:
# Simulate conversion failure
raise RuntimeError(f"Failed to convert '{filename}': Mock conversion error")
def supports(self, filename: str, content_type: str | None = None) -> bool:
return filename.endswith(".fail")
def name(self) -> str:
return "failing_converter"
# Register the failing parser
failing_converter = FailingParser()
memory_no_llm_verify._parser_registry.register(failing_converter)
# Create bank
context = RequestContext(internal=True)
await memory_no_llm_verify.get_bank_profile(bank_id, request_context=context)
# Create mock file
class MockFile:
def __init__(self, content, filename, content_type):
self.content = content
self.filename = filename
self.content_type = content_type
async def read(self):
return self.content
mock_file = MockFile(sample_txt_content, "test.fail", "application/octet-stream")
file_items = [
{
"file": mock_file,
"document_id": "test_doc_fail",
"context": None,
"metadata": {},
"tags": [],
"timestamp": None,
}
]
# Submit async file retain with failing parser
result = await memory_no_llm_verify.submit_async_file_retain(
bank_id=bank_id,
file_items=file_items,
parser="failing_converter",
document_tags=None,
request_context=context,
)
assert "operation_ids" in result
assert len(result["operation_ids"]) == 1
operation_id = result["operation_ids"][0]
# Wait for async processing (with SyncTaskBackend, this is immediate)
import asyncio
await asyncio.sleep(0.2)
# Check operation status - should be 'failed' not 'completed'
pool = await memory_no_llm_verify._get_pool()
from hindsight_api.engine.memory_engine import get_current_schema
async with pool.acquire() as conn:
operation = await conn.fetchrow(
f"""
SELECT status, error_message
FROM {get_current_schema()}.async_operations
WHERE operation_id = $1
""",
operation_id,
)
assert operation is not None, f"Operation {operation_id} not found"
assert operation["status"] == "failed", f"Expected status 'failed' but got '{operation['status']}'"
assert operation["error_message"] is not None
assert "Mock conversion error" in operation["error_message"]
assert "test.fail" in operation["error_message"]
-252
View File
@@ -1,252 +0,0 @@
"""
Integration tests for S3FileStorage against a SeaweedFS Docker container.
SeaweedFS (Apache 2.0) provides an S3-compatible API via `weed server -s3`.
Requires Docker to be running. Tests are skipped automatically if Docker is unavailable.
"""
import json
import logging
import subprocess
import tempfile
import time
import uuid
import httpx
import pytest
from httpx import ASGITransport, AsyncClient
logger = logging.getLogger(__name__)
try:
from testcontainers.core.container import DockerContainer
_has_testcontainers = True
except ImportError:
_has_testcontainers = False
pytestmark = [
pytest.mark.skipif(not _has_testcontainers, reason="testcontainers not installed"),
]
SEAWEEDFS_S3_PORT = 8333
TEST_BUCKET = "hindsight-test"
ACCESS_KEY = "test_access_key"
SECRET_KEY = "test_secret_key"
# SeaweedFS S3 IAM config granting full access to our test credentials
_S3_CONFIG = {
"identities": [
{
"name": "test-user",
"credentials": [{"accessKey": ACCESS_KEY, "secretKey": SECRET_KEY}],
"actions": ["Admin", "Read", "Write", "List"],
}
]
}
def _docker_available() -> bool:
"""Check if Docker daemon is running."""
try:
result = subprocess.run(
["docker", "info"],
capture_output=True,
timeout=5,
)
return result.returncode == 0
except (FileNotFoundError, subprocess.TimeoutExpired):
return False
def _wait_for_seaweedfs(endpoint: str, timeout: int = 30) -> None:
"""Poll SeaweedFS S3 endpoint until ready."""
deadline = time.time() + timeout
while time.time() < deadline:
try:
resp = httpx.get(endpoint, timeout=2)
# 200 = no auth, 403 = auth enabled but gateway is up — either means ready
if resp.status_code in (200, 403):
logger.info("SeaweedFS S3 is ready at %s", endpoint)
return
except httpx.HTTPError:
pass
time.sleep(0.5)
raise TimeoutError(f"SeaweedFS did not become ready at {endpoint} within {timeout}s")
@pytest.fixture(scope="module")
def seaweedfs_container():
"""Start a SeaweedFS container for the test module, shared across all tests.
Mounts an s3.json config file to set up S3 credentials for the test user.
"""
if not _docker_available():
pytest.skip("Docker is not available")
# Write S3 IAM config to a temp file that persists for the module scope
s3_config_file = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False)
json.dump(_S3_CONFIG, s3_config_file)
s3_config_file.flush()
container = (
DockerContainer(image="chrislusf/seaweedfs:latest")
.with_exposed_ports(SEAWEEDFS_S3_PORT)
.with_volume_mapping(s3_config_file.name, "/etc/seaweedfs/s3.json", "ro")
.with_command(
f"server -s3 -s3.port={SEAWEEDFS_S3_PORT} -s3.config=/etc/seaweedfs/s3.json -ip.bind=0.0.0.0"
)
)
container.start()
try:
host = container.get_container_host_ip()
port = container.get_exposed_port(SEAWEEDFS_S3_PORT)
endpoint = f"http://{host}:{port}"
_wait_for_seaweedfs(endpoint)
# Create test bucket using obstore (proper SigV4 signing)
import obstore as obs
from obstore.store import S3Store
admin_store = S3Store(
TEST_BUCKET,
endpoint=endpoint,
region="us-east-1",
access_key_id=ACCESS_KEY,
secret_access_key=SECRET_KEY,
allow_http=True,
)
# SeaweedFS auto-creates buckets on first write
obs.put(admin_store, ".bucket-init", b"")
obs.delete(admin_store, ".bucket-init")
logger.info("Test bucket '%s' is ready", TEST_BUCKET)
yield {
"endpoint": endpoint,
"access_key": ACCESS_KEY,
"secret_key": SECRET_KEY,
"bucket": TEST_BUCKET,
}
finally:
container.stop()
import os
os.unlink(s3_config_file.name)
@pytest.fixture
def s3_storage(seaweedfs_container):
"""Create an S3FileStorage instance pointing at the SeaweedFS container."""
from hindsight_api.engine.storage.s3 import S3FileStorage
return S3FileStorage(
bucket=seaweedfs_container["bucket"],
region="us-east-1",
endpoint=seaweedfs_container["endpoint"],
access_key_id=seaweedfs_container["access_key"],
secret_access_key=seaweedfs_container["secret_key"],
)
@pytest.mark.asyncio
async def test_s3_storage_store_and_retrieve(s3_storage):
"""Store a file, retrieve it, verify bytes match."""
content = b"Hello, SeaweedFS! This is a test file."
key = f"test/{uuid.uuid4()}.txt"
stored_key = await s3_storage.store(
file_data=content,
key=key,
metadata={"content_type": "text/plain"},
)
assert stored_key == key
retrieved = await s3_storage.retrieve(key)
assert retrieved == content
@pytest.mark.asyncio
async def test_s3_storage_exists_and_delete(s3_storage):
"""Store, check exists=True, delete, check exists=False."""
content = b"File to be deleted."
key = f"test/{uuid.uuid4()}.txt"
await s3_storage.store(file_data=content, key=key)
assert await s3_storage.exists(key) is True
await s3_storage.delete(key)
assert await s3_storage.exists(key) is False
@pytest.mark.asyncio
async def test_s3_storage_file_not_found(s3_storage):
"""Retrieve a non-existent key, expect FileNotFoundError."""
with pytest.raises(FileNotFoundError):
await s3_storage.retrieve(f"nonexistent/{uuid.uuid4()}.txt")
@pytest.mark.asyncio
async def test_s3_storage_get_download_url(s3_storage):
"""Store a file, get a presigned URL, verify it's a valid URL string."""
content = b"Presigned URL test content."
key = f"test/{uuid.uuid4()}.txt"
await s3_storage.store(file_data=content, key=key)
url = await s3_storage.get_download_url(key, expires_in=300)
assert isinstance(url, str)
assert url.startswith("http")
assert key in url
@pytest.mark.asyncio
async def test_s3_file_retain_api_end_to_end(seaweedfs_container, memory_no_llm_verify):
"""Full HTTP API flow: upload file via /files/retain with S3 storage backend."""
from hindsight_api.api.http import create_app
from hindsight_api.engine.storage.s3 import S3FileStorage
# Swap the engine's file storage to use the SeaweedFS-backed S3 storage
original_storage = memory_no_llm_verify._file_storage
s3_storage = S3FileStorage(
bucket=seaweedfs_container["bucket"],
region="us-east-1",
endpoint=seaweedfs_container["endpoint"],
access_key_id=seaweedfs_container["access_key"],
secret_access_key=seaweedfs_container["secret_key"],
)
memory_no_llm_verify._file_storage = s3_storage
try:
app = create_app(memory_no_llm_verify, initialize_memory=False)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
bank_id = f"test-s3-bank-{uuid.uuid4().hex[:8]}"
bank_response = await client.put(f"/v1/default/banks/{bank_id}", json={"name": "S3 Test Bank"})
assert bank_response.status_code in (200, 201)
txt_content = b"Alice works at Acme Corp. She joined in 2024."
request_data = {
"document_tags": ["s3-test"],
"async": True,
}
files = {"files": ("notes.txt", txt_content, "text/plain")}
data = {"request": json.dumps(request_data)}
response = await client.post(
f"/v1/default/banks/{bank_id}/files/retain",
files=files,
data=data,
)
assert response.status_code == 200
result = response.json()
assert "operation_ids" in result
assert len(result["operation_ids"]) == 1
finally:
memory_no_llm_verify._file_storage = original_storage
@@ -528,7 +528,7 @@ async def test_delete_bank(api_client):
{
"content": "Bob is the CTO and leads the engineering team.",
"context": "team info",
"document_id": "team-doc-2",
"document_id": "team-doc-1",
},
]
},
@@ -1,392 +0,0 @@
"""
Tests for LiteLLMSDKCrossEncoder.
Tests the LiteLLM SDK-based cross-encoder implementation for reranking.
"""
import os
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from hindsight_api.engine.cross_encoder import LiteLLMSDKCrossEncoder, create_cross_encoder_from_env
class TestLiteLLMSDKCrossEncoder:
"""Test suite for LiteLLMSDKCrossEncoder class."""
@pytest.mark.asyncio
async def test_initialization_success(self):
"""Test successful initialization with valid config."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="deepinfra/Qwen3-reranker-8B",
)
assert encoder.provider_name == "litellm-sdk"
assert encoder.api_key == "test_key"
assert encoder.model == "deepinfra/Qwen3-reranker-8B"
assert encoder._initialized is False
# Mock the litellm import
mock_litellm = MagicMock()
with patch.dict("sys.modules", {"litellm": mock_litellm}):
await encoder.initialize()
assert encoder._initialized is True
@pytest.mark.asyncio
async def test_initialization_missing_package(self):
"""Test initialization fails when litellm package is missing."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="cohere/rerank-english-v3.0",
)
with patch.dict("sys.modules", {"litellm": None}):
with pytest.raises(ImportError, match="litellm is required"):
await encoder.initialize()
@pytest.mark.asyncio
async def test_initialization_idempotent(self):
"""Test that calling initialize() multiple times is safe."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="cohere/rerank-english-v3.0",
)
mock_litellm = MagicMock()
with patch.dict("sys.modules", {"litellm": mock_litellm}):
await encoder.initialize()
assert encoder._initialized is True
# Second call should be no-op
await encoder.initialize()
assert encoder._initialized is True
@pytest.mark.asyncio
async def test_predict_single_query(self):
"""Test prediction with a single query and multiple documents."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="deepinfra/Qwen3-reranker-8B",
)
# Create mock response with results as TypedDicts
mock_response = MagicMock()
mock_response.results = [
{"index": 0, "relevance_score": 0.9},
{"index": 1, "relevance_score": 0.7},
{"index": 2, "relevance_score": 0.5},
]
mock_litellm = MagicMock()
mock_litellm.arerank = AsyncMock(return_value=mock_response)
with patch.dict("sys.modules", {"litellm": mock_litellm}):
await encoder.initialize()
pairs = [
("What is Python?", "Python is a programming language"),
("What is Python?", "Python is a snake"),
("What is Python?", "Python is a British comedy group"),
]
scores = await encoder.predict(pairs)
assert len(scores) == 3
assert scores == [0.9, 0.7, 0.5]
# Verify arerank was called correctly
mock_litellm.arerank.assert_called_once()
call_args = mock_litellm.arerank.call_args
assert call_args.kwargs["model"] == "deepinfra/Qwen3-reranker-8B"
assert call_args.kwargs["query"] == "What is Python?"
assert len(call_args.kwargs["documents"]) == 3
assert call_args.kwargs["api_key"] == "test_key"
@pytest.mark.asyncio
async def test_predict_multiple_queries(self):
"""Test prediction with multiple different queries (grouped efficiently)."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="cohere/rerank-english-v3.0",
)
# First query response
mock_response1 = MagicMock()
mock_response1.results = [
{"index": 0, "relevance_score": 0.9},
{"index": 1, "relevance_score": 0.7},
]
# Second query response
mock_response2 = MagicMock()
mock_response2.results = [
{"index": 0, "relevance_score": 0.8},
]
mock_litellm = MagicMock()
mock_litellm.arerank = AsyncMock(side_effect=[mock_response1, mock_response2])
with patch.dict("sys.modules", {"litellm": mock_litellm}):
await encoder.initialize()
pairs = [
("What is Python?", "Python is a programming language"),
("What is Python?", "Python is a snake"),
("What is Java?", "Java is a programming language"),
]
scores = await encoder.predict(pairs)
assert len(scores) == 3
assert scores[0] == 0.9 # First query, first doc
assert scores[1] == 0.7 # First query, second doc
assert scores[2] == 0.8 # Second query, first doc
# Verify arerank was called twice (once per unique query)
assert mock_litellm.arerank.call_count == 2
@pytest.mark.asyncio
async def test_predict_empty_pairs(self):
"""Test prediction with empty input."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="cohere/rerank-english-v3.0",
)
mock_litellm = MagicMock()
with patch.dict("sys.modules", {"litellm": mock_litellm}):
await encoder.initialize()
scores = await encoder.predict([])
assert scores == []
@pytest.mark.asyncio
async def test_predict_not_initialized(self):
"""Test that predict fails if encoder not initialized."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="cohere/rerank-english-v3.0",
)
pairs = [("query", "document")]
with pytest.raises(RuntimeError, match="not initialized"):
await encoder.predict(pairs)
@pytest.mark.asyncio
async def test_predict_error_handling(self):
"""Test that errors during prediction are raised."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="cohere/rerank-english-v3.0",
)
# Mock litellm to raise an error
mock_litellm = MagicMock()
mock_litellm.arerank = AsyncMock(side_effect=Exception("API Error"))
with patch.dict("sys.modules", {"litellm": mock_litellm}):
await encoder.initialize()
pairs = [
("What is Python?", "Python is a programming language"),
]
# Should raise the exception
with pytest.raises(Exception, match="API Error"):
await encoder.predict(pairs)
@pytest.mark.asyncio
async def test_custom_api_base(self):
"""Test that custom API base URL is passed to rerank calls."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="cohere/rerank-english-v3.0",
api_base="https://custom.api.example.com",
)
mock_response = MagicMock()
mock_response.results = [
{"index": 0, "relevance_score": 0.9},
]
mock_litellm = MagicMock()
mock_litellm.arerank = AsyncMock(return_value=mock_response)
with patch.dict("sys.modules", {"litellm": mock_litellm}):
await encoder.initialize()
# Test that api_base is passed to arerank
pairs = [("query", "document")]
scores = await encoder.predict(pairs)
assert scores == [0.9]
mock_litellm.arerank.assert_called_once()
call_args = mock_litellm.arerank.call_args
assert call_args.kwargs["api_base"] == "https://custom.api.example.com"
@pytest.mark.asyncio
async def test_response_with_direct_score_list(self):
"""Test handling of response format with direct score list."""
encoder = LiteLLMSDKCrossEncoder(
api_key="test_key",
model="some-provider/model",
)
# Mock litellm to return direct list of scores
mock_litellm = MagicMock()
mock_litellm.arerank = AsyncMock(return_value=[0.9, 0.7, 0.5])
with patch.dict("sys.modules", {"litellm": mock_litellm}):
await encoder.initialize()
pairs = [
("query", "doc1"),
("query", "doc2"),
("query", "doc3"),
]
scores = await encoder.predict(pairs)
assert scores == [0.9, 0.7, 0.5]
class TestFactoryFunction:
"""Test suite for create_cross_encoder_from_env factory function."""
@pytest.mark.asyncio
async def test_create_litellm_sdk_from_env(self):
"""Test creating LiteLLM SDK cross-encoder from environment variables."""
env_vars = {
"HINDSIGHT_API_RERANKER_PROVIDER": "litellm-sdk",
"HINDSIGHT_API_RERANKER_LITELLM_SDK_API_KEY": "test_key",
"HINDSIGHT_API_RERANKER_LITELLM_SDK_MODEL": "deepinfra/Qwen3-reranker-8B",
}
with patch.dict(os.environ, env_vars, clear=False):
# Need to reload config to pick up env vars
from hindsight_api.config import HindsightConfig
config = HindsightConfig.from_env()
with patch("hindsight_api.config.get_config", return_value=config):
encoder = create_cross_encoder_from_env()
assert isinstance(encoder, LiteLLMSDKCrossEncoder)
assert encoder.api_key == "test_key"
assert encoder.model == "deepinfra/Qwen3-reranker-8B"
@pytest.mark.asyncio
async def test_create_litellm_sdk_missing_api_key(self):
"""Test that factory raises error when API key is missing."""
env_vars = {
"HINDSIGHT_API_RERANKER_PROVIDER": "litellm-sdk",
"HINDSIGHT_API_RERANKER_LITELLM_SDK_MODEL": "deepinfra/Qwen3-reranker-8B",
}
with patch.dict(os.environ, env_vars, clear=False):
# Remove API key if set
if "HINDSIGHT_API_RERANKER_LITELLM_SDK_API_KEY" in os.environ:
del os.environ["HINDSIGHT_API_RERANKER_LITELLM_SDK_API_KEY"]
from hindsight_api.config import HindsightConfig
config = HindsightConfig.from_env()
with patch("hindsight_api.config.get_config", return_value=config):
with pytest.raises(ValueError, match="HINDSIGHT_API_RERANKER_LITELLM_SDK_API_KEY is required"):
create_cross_encoder_from_env()
@pytest.mark.asyncio
async def test_create_litellm_sdk_with_custom_api_base(self):
"""Test creating LiteLLM SDK cross-encoder with custom API base."""
env_vars = {
"HINDSIGHT_API_RERANKER_PROVIDER": "litellm-sdk",
"HINDSIGHT_API_RERANKER_LITELLM_SDK_API_KEY": "test_key",
"HINDSIGHT_API_RERANKER_LITELLM_SDK_MODEL": "cohere/rerank-english-v3.0",
"HINDSIGHT_API_RERANKER_LITELLM_SDK_API_BASE": "https://custom.api.example.com",
}
with patch.dict(os.environ, env_vars, clear=False):
from hindsight_api.config import HindsightConfig
config = HindsightConfig.from_env()
with patch("hindsight_api.config.get_config", return_value=config):
encoder = create_cross_encoder_from_env()
assert isinstance(encoder, LiteLLMSDKCrossEncoder)
assert encoder.api_base == "https://custom.api.example.com"
class TestLiteLLMSDKCohereCrossEncoder:
"""Tests for LiteLLM SDK calling Cohere (runs in CI with COHERE_API_KEY)."""
@pytest.fixture
async def litellm_cohere_cross_encoder(self):
"""Create LiteLLM SDK cross-encoder instance for Cohere."""
if not os.environ.get("COHERE_API_KEY"):
pytest.skip("Cohere API key not available (set COHERE_API_KEY)")
encoder = LiteLLMSDKCrossEncoder(
api_key=os.environ["COHERE_API_KEY"],
model="cohere/rerank-english-v3.0",
)
await encoder.initialize()
return encoder
@pytest.mark.asyncio
async def test_litellm_sdk_cohere_initialization(self, litellm_cohere_cross_encoder):
"""Test that LiteLLM SDK Cohere cross-encoder initializes correctly."""
assert litellm_cohere_cross_encoder.provider_name == "litellm-sdk"
assert litellm_cohere_cross_encoder.model == "cohere/rerank-english-v3.0"
@pytest.mark.asyncio
async def test_litellm_sdk_cohere_predict(self, litellm_cohere_cross_encoder):
"""Test that LiteLLM SDK can call Cohere rerank API."""
pairs = [
("What is the capital of France?", "Paris is the capital of France."),
("What is the capital of France?", "The Eiffel Tower is in Paris."),
("What is the capital of France?", "Python is a programming language."),
]
scores = await litellm_cohere_cross_encoder.predict(pairs)
assert len(scores) == 3
assert all(isinstance(s, float) for s in scores)
# The first result should be most relevant
assert scores[0] > scores[2], "Direct answer should score higher than unrelated text"
# All scores should be in valid range
assert all(0.0 <= score <= 1.0 for score in scores)
class TestIntegration:
"""Integration tests with real API (optional - requires API keys)."""
@pytest.mark.skipif(
not os.environ.get("DEEPINFRA_API_KEY"),
reason="DEEPINFRA_API_KEY not set - skipping integration test",
)
@pytest.mark.asyncio
async def test_real_deepinfra_api(self):
"""Test with real DeepInfra API (requires DEEPINFRA_API_KEY env var)."""
encoder = LiteLLMSDKCrossEncoder(
api_key=os.environ["DEEPINFRA_API_KEY"],
model="deepinfra/Qwen3-reranker-8B",
)
await encoder.initialize()
pairs = [
("What is Python?", "Python is a high-level programming language"),
("What is Python?", "Python is a species of snake"),
("What is Python?", "Python is unrelated text about cars"),
]
scores = await encoder.predict(pairs)
# First doc should have highest score (most relevant)
assert len(scores) == 3
assert scores[0] > scores[1]
assert scores[1] > scores[2]
assert all(0.0 <= score <= 1.0 for score in scores)
@@ -1,387 +0,0 @@
"""
Tests for LiteLLM SDK embeddings implementation.
These tests cover:
1. Initialization (success, missing package, missing API key, idempotent)
2. Encode (single text, multiple texts, batching, error handling)
3. Provider-specific configuration (Cohere, OpenAI, etc.)
4. Factory function (create from env, validation errors)
5. Dimension detection
"""
import os
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from hindsight_api.config import (
ENV_EMBEDDINGS_LITELLM_SDK_API_KEY,
ENV_EMBEDDINGS_LITELLM_SDK_MODEL,
ENV_EMBEDDINGS_PROVIDER,
HindsightConfig,
)
from hindsight_api.engine.embeddings import LiteLLMSDKEmbeddings, create_embeddings_from_env
class TestLiteLLMSDKEmbeddings:
"""Unit tests for LiteLLMSDKEmbeddings with mocked litellm responses."""
@pytest.fixture
def mock_litellm(self):
"""Mock litellm module."""
mock = MagicMock()
# Mock aembedding (async) for initialization
mock_response = MagicMock()
mock_response.data = [{"embedding": [0.1] * 768, "index": 0}]
mock.aembedding = AsyncMock(return_value=mock_response)
# Mock embedding (sync) for encode
mock_sync_response = MagicMock()
mock_sync_response.data = [
{"embedding": [0.1] * 768, "index": 0},
{"embedding": [0.2] * 768, "index": 1},
]
mock.embedding = MagicMock(return_value=mock_sync_response)
return mock
@pytest.fixture
async def embeddings(self, mock_litellm):
"""Create initialized LiteLLMSDKEmbeddings instance."""
emb = LiteLLMSDKEmbeddings(
api_key="test_key",
model="cohere/embed-english-v3.0",
api_base=None,
batch_size=100,
timeout=60.0,
)
# Manually set the mock (simulating successful initialization)
emb._litellm = mock_litellm
emb._dimension = 768
return emb
async def test_initialization_success(self, mock_litellm):
"""Test successful initialization."""
with patch("builtins.__import__", side_effect=lambda name, *args: mock_litellm if name == "litellm" else __import__(name, *args)):
emb = LiteLLMSDKEmbeddings(
api_key="test_key",
model="cohere/embed-english-v3.0",
api_base=None,
batch_size=100,
timeout=60.0,
)
assert emb._litellm is None
assert emb._dimension is None
await emb.initialize()
assert emb._litellm is not None
assert emb._dimension == 768
# Verify test embedding was called
mock_litellm.aembedding.assert_called_once_with(
model="cohere/embed-english-v3.0",
input=["test"],
api_key="test_key",
)
async def test_initialization_missing_package(self):
"""Test initialization fails gracefully when litellm is not installed."""
def mock_import(name, *args):
if name == "litellm":
raise ImportError("No module named 'litellm'")
return __import__(name, *args)
with patch("builtins.__import__", side_effect=mock_import):
emb = LiteLLMSDKEmbeddings(
api_key="test_key",
model="cohere/embed-english-v3.0",
api_base=None,
batch_size=100,
timeout=60.0,
)
with pytest.raises(ImportError, match="litellm is required"):
await emb.initialize()
async def test_initialization_idempotent(self, embeddings, mock_litellm):
"""Test that calling initialize() multiple times is safe."""
# embeddings._litellm is already set in fixture
assert embeddings._litellm is not None
# Call again
await embeddings.initialize()
# Should still have same litellm instance
assert embeddings._litellm is not None
async def test_encode_single_text(self, embeddings, mock_litellm):
"""Test encoding a single text."""
# Set up mock response
mock_litellm.embedding.return_value.data = [
{"embedding": [0.5] * 768, "index": 0},
]
result = embeddings.encode(["Hello world"])
assert isinstance(result, list)
assert len(result) == 1
assert len(result[0]) == 768
assert all(isinstance(x, float) for x in result[0])
assert all(abs(x - 0.5) < 0.001 for x in result[0])
# Verify call
mock_litellm.embedding.assert_called_once_with(
model="cohere/embed-english-v3.0",
input=["Hello world"],
api_key="test_key",
)
async def test_encode_multiple_texts(self, embeddings, mock_litellm):
"""Test encoding multiple texts."""
# Set up mock response
mock_litellm.embedding.return_value.data = [
{"embedding": [0.1] * 768, "index": 0},
{"embedding": [0.2] * 768, "index": 1},
{"embedding": [0.3] * 768, "index": 2},
]
texts = ["First text", "Second text", "Third text"]
result = embeddings.encode(texts)
assert isinstance(result, list)
assert len(result) == 3
assert len(result[0]) == 768
assert len(result[1]) == 768
assert len(result[2]) == 768
assert all(abs(x - 0.1) < 0.001 for x in result[0])
assert all(abs(x - 0.2) < 0.001 for x in result[1])
assert all(abs(x - 0.3) < 0.001 for x in result[2])
async def test_encode_batching(self, embeddings, mock_litellm):
"""Test that large inputs are batched correctly."""
# Create embeddings with small batch size
emb = LiteLLMSDKEmbeddings(
api_key="test_key",
model="cohere/embed-english-v3.0",
api_base=None,
batch_size=2, # Small batch for testing
timeout=60.0,
)
emb._litellm = mock_litellm
emb._initialized = True
emb._dimension = 768
# Mock responses for each batch
def mock_embedding_side_effect(model, input, **kwargs):
mock_response = MagicMock()
mock_response.data = [
{"embedding": [float(i)] * 768, "index": i} for i in range(len(input))
]
return mock_response
mock_litellm.embedding.side_effect = mock_embedding_side_effect
# Encode 5 texts (should create 3 batches: 2, 2, 1)
texts = [f"Text {i}" for i in range(5)]
result = emb.encode(texts)
assert isinstance(result, list)
assert len(result) == 5
assert all(len(embedding) == 768 for embedding in result)
# Verify batching: should be called 3 times
assert mock_litellm.embedding.call_count == 3
# Verify batch sizes
calls = mock_litellm.embedding.call_args_list
assert len(calls[0][1]["input"]) == 2 # First batch
assert len(calls[1][1]["input"]) == 2 # Second batch
assert len(calls[2][1]["input"]) == 1 # Third batch
async def test_encode_empty_list(self, embeddings):
"""Test encoding empty list returns empty list."""
result = embeddings.encode([])
assert isinstance(result, list)
assert len(result) == 0
async def test_encode_before_initialization(self, mock_litellm):
"""Test that encode raises error if not initialized."""
emb = LiteLLMSDKEmbeddings(
api_key="test_key",
model="cohere/embed-english-v3.0",
api_base=None,
batch_size=100,
timeout=60.0,
)
with pytest.raises(RuntimeError, match="not initialized"):
emb.encode(["test"])
async def test_encode_error_handling(self, embeddings, mock_litellm):
"""Test error handling during encoding."""
# Make embedding raise an error
mock_litellm.embedding.side_effect = Exception("API Error")
with pytest.raises(Exception, match="API Error"):
embeddings.encode(["test"])
async def test_dimension_property(self, embeddings):
"""Test dimension property."""
assert embeddings.dimension == 768
async def test_dimension_before_initialization(self, mock_litellm):
"""Test dimension raises error if not initialized."""
emb = LiteLLMSDKEmbeddings(
api_key="test_key",
model="cohere/embed-english-v3.0",
api_base=None,
batch_size=100,
timeout=60.0,
)
with pytest.raises(RuntimeError, match="not initialized"):
_ = emb.dimension
async def test_custom_api_base(self, mock_litellm):
"""Test custom API base URL is passed to embedding calls."""
with patch("builtins.__import__", side_effect=lambda name, *args: mock_litellm if name == "litellm" else __import__(name, *args)):
emb = LiteLLMSDKEmbeddings(
api_key="test_key",
model="cohere/embed-english-v3.0",
api_base="https://custom.api.com",
batch_size=100,
timeout=60.0,
)
await emb.initialize()
# Verify api_base is set
assert emb.api_base == "https://custom.api.com"
# Verify api_base is passed to aembedding
mock_litellm.aembedding.assert_called_once()
call_args = mock_litellm.aembedding.call_args
assert call_args.kwargs["api_base"] == "https://custom.api.com"
# Test encode also passes api_base
mock_litellm.embedding.return_value.data = [{"embedding": [0.1] * 768, "index": 0}]
emb.encode(["test"])
mock_litellm.embedding.assert_called_once()
call_args = mock_litellm.embedding.call_args
assert call_args.kwargs["api_base"] == "https://custom.api.com"
class TestLiteLLMSDKEmbeddingsFactory:
"""Test the factory function for creating LiteLLM SDK embeddings."""
def test_create_from_env_success(self, monkeypatch):
"""Test creating embeddings from environment variables."""
# Mock get_config() to return configured HindsightConfig
mock_config = MagicMock()
mock_config.embeddings_provider = "litellm-sdk"
mock_config.embeddings_litellm_sdk_api_key = "test_key"
mock_config.embeddings_litellm_sdk_model = "cohere/embed-english-v3.0"
mock_config.embeddings_litellm_sdk_api_base = None
with patch("hindsight_api.config.get_config", return_value=mock_config):
embeddings = create_embeddings_from_env()
assert isinstance(embeddings, LiteLLMSDKEmbeddings)
assert embeddings.api_key == "test_key"
assert embeddings.model == "cohere/embed-english-v3.0"
def test_create_from_env_missing_api_key(self, monkeypatch):
"""Test that missing API key raises error."""
# Mock get_config() with missing API key
mock_config = MagicMock()
mock_config.embeddings_provider = "litellm-sdk"
mock_config.embeddings_litellm_sdk_api_key = None # Missing key
mock_config.embeddings_litellm_sdk_model = "cohere/embed-english-v3.0"
with patch("hindsight_api.config.get_config", return_value=mock_config):
with pytest.raises(ValueError, match=ENV_EMBEDDINGS_LITELLM_SDK_API_KEY):
create_embeddings_from_env()
def test_create_from_env_with_api_base(self, monkeypatch):
"""Test creating embeddings with custom API base."""
# Mock get_config() with custom API base
mock_config = MagicMock()
mock_config.embeddings_provider = "litellm-sdk"
mock_config.embeddings_litellm_sdk_api_key = "test_key"
mock_config.embeddings_litellm_sdk_model = "cohere/embed-english-v3.0"
mock_config.embeddings_litellm_sdk_api_base = "https://custom.api.com"
with patch("hindsight_api.config.get_config", return_value=mock_config):
embeddings = create_embeddings_from_env()
assert isinstance(embeddings, LiteLLMSDKEmbeddings)
assert embeddings.api_base == "https://custom.api.com"
class TestLiteLLMSDKCohereEmbeddings:
"""Integration tests calling real Cohere API (matches CI pattern)."""
@pytest.fixture
async def litellm_cohere_embeddings(self):
"""Create embeddings instance with real Cohere API key."""
if not os.environ.get("COHERE_API_KEY"):
pytest.skip("Cohere API key not available")
emb = LiteLLMSDKEmbeddings(
api_key=os.environ["COHERE_API_KEY"],
model="cohere/embed-english-v3.0",
api_base=None,
batch_size=100,
timeout=60.0,
)
await emb.initialize()
return emb
@pytest.mark.asyncio
async def test_litellm_sdk_cohere_encode(self, litellm_cohere_embeddings):
"""Test real Cohere API call for embeddings."""
texts = [
"The quick brown fox jumps over the lazy dog",
"Machine learning is a subset of artificial intelligence",
"Python is a popular programming language",
]
result = litellm_cohere_embeddings.encode(texts)
# Verify result type and shape
assert isinstance(result, list)
assert len(result) == 3
assert all(len(embedding) > 0 for embedding in result)
assert all(isinstance(x, float) for x in result[0])
# Verify embeddings are not zeros (common API failure mode)
for i, embedding in enumerate(result):
assert not all(abs(x) < 0.0001 for x in embedding), f"Embedding {i} is all zeros"
# Verify embeddings are normalized (Cohere returns normalized vectors)
for i, embedding in enumerate(result):
norm = sum(x * x for x in embedding) ** 0.5
assert 0.9 < norm < 1.1, f"Embedding {i} norm {norm} is not close to 1.0"
@pytest.mark.asyncio
async def test_litellm_sdk_cohere_dimension(self, litellm_cohere_embeddings):
"""Test dimension detection with real Cohere API."""
dimension = litellm_cohere_embeddings.dimension
# Cohere embed-english-v3.0 has 1024 dimensions
assert dimension == 1024
@pytest.mark.asyncio
async def test_litellm_sdk_cohere_single_text(self, litellm_cohere_embeddings):
"""Test encoding single text with real Cohere API."""
result = litellm_cohere_embeddings.encode(["Hello world"])
assert isinstance(result, list)
assert len(result) == 1
assert len(result[0]) == 1024
assert not all(abs(x) < 0.0001 for x in result[0])
-41
View File
@@ -352,47 +352,6 @@ class TestMainModuleExtensionLoading:
"main.py should use import string when workers > 1"
assert uvicorn_calls[0]["workers"] == 2
def test_main_sets_keepalive_timeout(self, monkeypatch):
"""
Verify that uvicorn is configured with timeout_keep_alive > aiohttp's
default client keepalive timeout (15s), so the server never closes
connections before the client does.
"""
monkeypatch.setenv("HINDSIGHT_API_WORKERS", "1")
monkeypatch.delenv("HINDSIGHT_API_TENANT_EXTENSION", raising=False)
uvicorn_calls = []
def capture_uvicorn_run(**kwargs):
uvicorn_calls.append(kwargs)
with patch("hindsight_api.main.MemoryEngine") as mock_engine, \
patch("hindsight_api.main.create_app") as mock_create_app, \
patch("hindsight_api.main._get_raw_config") as mock_get_config, \
patch("hindsight_api.main.print_banner"), \
patch("uvicorn.run", side_effect=capture_uvicorn_run):
mock_config = MagicMock()
mock_config.host = "0.0.0.0"
mock_config.port = 8888
mock_config.log_level = "info"
mock_config.mcp_enabled = False
mock_config.run_migrations_on_startup = False
mock_config.database_url = "postgresql://test:test@localhost/test"
mock_get_config.return_value = mock_config
mock_engine.return_value = MagicMock()
mock_create_app.return_value = MagicMock()
with patch.object(sys, 'argv', ['hindsight-api']):
from hindsight_api.main import main
main()
assert len(uvicorn_calls) == 1
assert "timeout_keep_alive" in uvicorn_calls[0], \
"uvicorn config must set timeout_keep_alive"
assert uvicorn_calls[0]["timeout_keep_alive"] > 15, \
"timeout_keep_alive must exceed aiohttp's 15s client default"
# Mock extensions for testing
from hindsight_api.extensions import (
@@ -1,274 +0,0 @@
"""
Test that recall chunks are fetched independently of max_tokens filtering.
This test verifies the new behavior where:
1. Chunks are fetched BEFORE max_tokens filtering
2. max_tokens=0 returns 0 facts but can still return chunks
3. Chunks are fetched in batches to handle varying chunk sizes
"""
import pytest
import pytest_asyncio
from hindsight_api.engine.memory_engine import Budget
@pytest.mark.asyncio
async def test_recall_chunks_independent_of_max_tokens(memory, request_context):
"""
Test that chunks are fetched independently of max_tokens.
When max_tokens=0, recall should:
- Return 0 memory facts
- Still return chunks (up to max_chunk_tokens)
- Chunks should come from top-scored results before token filtering
"""
bank_id = "test-chunks-independence"
try:
# Retain some test content with substantial size to generate chunks
test_content = """
The quantum computing research team at MIT has made significant breakthroughs.
Dr. Sarah Chen leads the team and focuses on quantum error correction.
The team published three papers in Nature Physics this year.
Their work on topological qubits shows promise for scalable quantum computers.
Collaborators include IBM Research and Google Quantum AI.
The research is funded by a $5M NSF grant running through 2026.
""" * 10 # Repeat to ensure we get multiple chunks
await memory.retain_async(
bank_id=bank_id,
content=test_content,
context="research notes",
request_context=request_context,
)
# Test 1: Normal recall with both facts and chunks
result_normal = await memory.recall_async(
bank_id=bank_id,
query="quantum computing",
max_tokens=4096, # Normal token budget
include_chunks=True,
max_chunk_tokens=2000,
budget=Budget.MID,
request_context=request_context,
)
assert len(result_normal.results) > 0, "Should return memory facts with normal max_tokens"
assert result_normal.chunks is not None, "Should include chunks when requested"
assert len(result_normal.chunks) > 0, "Should return at least one chunk"
# Test 2: Recall with max_tokens=0 but chunks enabled
result_chunks_only = await memory.recall_async(
bank_id=bank_id,
query="quantum computing",
max_tokens=0, # Zero token budget for facts
include_chunks=True,
max_chunk_tokens=2000, # But allow chunks
budget=Budget.MID,
request_context=request_context,
)
# Key assertions for new behavior
assert len(result_chunks_only.results) == 0, "max_tokens=0 should return 0 facts"
assert result_chunks_only.chunks is not None, "Should still include chunks dict"
assert len(result_chunks_only.chunks) > 0, "Should return chunks even with max_tokens=0"
# Verify chunks are from the same content (non-empty text)
for chunk_id, chunk_info in result_chunks_only.chunks.items():
assert len(chunk_info.chunk_text) > 0, "Chunks should contain text"
assert chunk_info.chunk_index >= 0, "Chunk should have valid index"
finally:
# Cleanup
await memory.delete_bank(bank_id, request_context=request_context)
@pytest.mark.asyncio
async def test_recall_chunks_batching_with_varying_sizes(memory, request_context):
"""
Test that chunk batching works correctly with varying chunk sizes.
This verifies that:
1. Chunks are fetched in batches until token budget is exhausted
2. The system handles varying chunk sizes across documents
3. Token budget is respected across multiple batch fetches
"""
bank_id = "test-chunks-batching"
try:
# Retain multiple documents with different content sizes
# Document 1: Short content (small chunks)
await memory.retain_async(
bank_id=bank_id,
content="Alice is a software engineer who specializes in Python programming and machine learning.",
context="doc1",
request_context=request_context,
)
# Document 2: Medium content
content_bob = """
Bob works as a data scientist at a tech startup in San Francisco.
He has expertise in natural language processing and computer vision.
Bob completed his PhD at Stanford University in 2020.
He leads a team of five engineers working on AI-powered recommendation systems.
""" * 5
await memory.retain_async(
bank_id=bank_id,
content=content_bob,
context="doc2",
request_context=request_context,
)
# Document 3: Long content (large chunks)
content_charlie = """
Charlie is the CTO of a growing AI company focused on healthcare applications.
He has over 15 years of experience in software architecture and distributed systems.
Charlie's team builds machine learning models for medical image analysis and diagnosis.
The company recently raised $50 million in Series B funding.
They have partnerships with major hospitals in the United States and Europe.
Charlie holds several patents in medical imaging and deep learning.
""" * 20
await memory.retain_async(
bank_id=bank_id,
content=content_charlie,
context="doc3",
request_context=request_context,
)
# Recall with modest chunk token budget
result = await memory.recall_async(
bank_id=bank_id,
query="Alice Bob Charlie",
max_tokens=0, # No facts, only chunks
include_chunks=True,
max_chunk_tokens=1000, # Limited chunk budget
budget=Budget.MID,
request_context=request_context,
)
assert len(result.results) == 0, "Should return 0 facts with max_tokens=0"
assert result.chunks is not None, "Should include chunks"
# Verify we got chunks and respected the token budget
if len(result.chunks) > 0:
# Count total tokens (approximate)
total_chunk_chars = sum(len(chunk.chunk_text) for chunk in result.chunks.values())
# Very rough estimate: 1 token ≈ 4 characters
estimated_tokens = total_chunk_chars // 4
# Should be reasonably close to budget (within 2x due to estimation and batching)
assert estimated_tokens <= 1000 * 2, f"Should respect chunk token budget (got ~{estimated_tokens} tokens)"
finally:
# Cleanup
await memory.delete_bank(bank_id, request_context=request_context)
@pytest.mark.asyncio
async def test_recall_chunks_ordering_by_relevance(memory, request_context):
"""
Test that chunks are returned in order of fact relevance.
Chunks should be ordered based on the top-scored (reranked) results,
not in document order or random order.
"""
bank_id = "test-chunks-ordering"
try:
# Retain content with different relevance to query
await memory.retain_async(
bank_id=bank_id,
content="The Python programming language is widely used for machine learning and data science applications.",
context="topic: Python",
request_context=request_context,
)
await memory.retain_async(
bank_id=bank_id,
content="JavaScript is commonly used for web development and frontend applications.",
context="topic: JavaScript",
request_context=request_context,
)
await memory.retain_async(
bank_id=bank_id,
content="Python's scikit-learn library is excellent for traditional machine learning tasks and model training.",
context="topic: Python ML",
request_context=request_context,
)
# Query specifically about Python - should rank Python facts higher
result = await memory.recall_async(
bank_id=bank_id,
query="Python machine learning",
max_tokens=0, # No facts
include_chunks=True,
max_chunk_tokens=5000, # Enough for all chunks
budget=Budget.HIGH, # Use high budget for better recall
request_context=request_context,
)
assert len(result.results) == 0, "Should return 0 facts with max_tokens=0"
assert result.chunks is not None, "Should include chunks"
# We should get chunks, and they should be ordered by relevance
# The exact ordering depends on the reranker, but we should have chunks
assert len(result.chunks) > 0, "Should return chunks from relevant facts"
# Verify chunks contain relevant content
all_chunk_text = " ".join(chunk.chunk_text for chunk in result.chunks.values())
# At least some chunks should mention Python (higher relevance)
# This is a soft check since exact ordering depends on scoring
assert "Python" in all_chunk_text or "python" in all_chunk_text.lower(), \
"Chunks should include content about Python (relevant to query)"
finally:
# Cleanup
await memory.delete_bank(bank_id, request_context=request_context)
@pytest.mark.asyncio
async def test_recall_chunks_without_include_flag(memory, request_context):
"""
Test that chunks are NOT returned when include_chunks=False (default).
This ensures backward compatibility - chunks are only fetched when explicitly requested.
"""
bank_id = "test-chunks-no-include"
try:
# Retain content
test_content = """
Sarah is a product manager at a fintech company in New York.
She specializes in user experience design and agile methodologies.
Sarah graduated from MIT with a degree in computer science.
She has led the development of three successful mobile banking applications.
"""
await memory.retain_async(
bank_id=bank_id,
content=test_content,
request_context=request_context,
)
# Recall without include_chunks flag (default is False)
result = await memory.recall_async(
bank_id=bank_id,
query="Sarah product manager",
max_tokens=4096,
request_context=request_context,
# include_chunks=False is the default
)
# Should have facts but no chunks
assert len(result.results) > 0, "Should return facts"
assert result.chunks is None or len(result.chunks) == 0, \
"Should NOT return chunks when include_chunks=False"
finally:
# Cleanup
await memory.delete_bank(bank_id, request_context=request_context)
+30 -70
View File
@@ -206,12 +206,8 @@ class TestWorkerPoller:
assert len(claimed) == 3
@pytest.mark.asyncio
async def test_execute_task_executor_marks_completed(self, pool, clean_operations):
"""Test that executor's status marking is preserved by the poller.
The executor (MemoryEngine.execute_task) handles marking operations as completed/failed.
The poller should NOT override those status updates.
"""
async def test_execute_task_marks_completed(self, pool, clean_operations):
"""Test that successful task execution marks task as completed."""
from hindsight_api.worker import WorkerPoller
from hindsight_api.worker.poller import ClaimedTask
@@ -232,16 +228,7 @@ class TestWorkerPoller:
executed = []
async def mock_executor(task_dict):
"""Executor that marks its own status as completed (like MemoryEngine.execute_task)."""
executed.append(task_dict)
await pool.execute(
"""
UPDATE async_operations
SET status = 'completed', completed_at = now(), updated_at = now()
WHERE operation_id = $1
""",
op_id,
)
poller = WorkerPoller(
pool=pool,
@@ -259,7 +246,7 @@ class TestWorkerPoller:
assert completed, "Task did not complete within timeout"
assert len(executed) == 1
# Verify task is marked as completed (by executor, not overridden by poller)
# Verify task is marked as completed
row = await pool.fetchrow(
"SELECT status, completed_at FROM async_operations WHERE operation_id = $1",
op_id,
@@ -268,24 +255,19 @@ class TestWorkerPoller:
assert row["completed_at"] is not None
@pytest.mark.asyncio
async def test_executor_exception_does_not_crash_poller(self, pool, clean_operations):
"""Test that unexpected exceptions from executor are caught and don't crash the poller.
If the executor raises an unexpected exception (which MemoryEngine.execute_task should NOT do,
but could happen from schema setup or other infrastructure issues), the poller should catch it
gracefully. Status remains 'processing' since neither executor nor poller handled it.
"""
async def test_execute_task_retries_on_failure(self, pool, clean_operations):
"""Test that failed task execution triggers retry mechanism."""
from hindsight_api.worker import WorkerPoller
from hindsight_api.worker.poller import ClaimedTask
# Create a pending task
# Create a pending task with retry_count=0
bank_id = f"test-worker-{uuid.uuid4().hex[:8]}"
op_id = uuid.uuid4()
payload = json.dumps({"type": "test_task", "operation_id": str(op_id), "bank_id": bank_id})
await pool.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, status, task_payload, worker_id)
VALUES ($1, $2, 'test', 'processing', $3::jsonb, 'test-worker-1')
INSERT INTO async_operations (operation_id, bank_id, operation_type, status, task_payload, worker_id, retry_count)
VALUES ($1, $2, 'test', 'processing', $3::jsonb, 'test-worker-1', 0)
""",
op_id,
bank_id,
@@ -293,15 +275,16 @@ class TestWorkerPoller:
)
async def failing_executor(task_dict):
raise ValueError("Unexpected infrastructure failure")
raise ValueError("Simulated failure")
poller = WorkerPoller(
pool=pool,
worker_id="test-worker-1",
executor=failing_executor,
max_retries=3,
)
# Execute - should catch exception without crashing
# Execute (should fail and retry) - fire-and-forget
task_dict = json.loads(payload)
claimed_task = ClaimedTask(operation_id=str(op_id), task_dict=task_dict, schema=None)
await poller.execute_task(claimed_task)
@@ -310,84 +293,61 @@ class TestWorkerPoller:
completed = await poller.wait_for_active_tasks(timeout=5.0)
assert completed, "Task did not complete within timeout"
# Status stays 'processing' since the poller no longer manages status
# Verify task is back to pending with incremented retry_count
row = await pool.fetchrow(
"SELECT status FROM async_operations WHERE operation_id = $1",
"SELECT status, retry_count, worker_id FROM async_operations WHERE operation_id = $1",
op_id,
)
assert row["status"] == "processing"
assert row["status"] == "pending"
assert row["retry_count"] == 1
assert row["worker_id"] is None # Worker ID cleared for retry
@pytest.mark.asyncio
async def test_executor_failed_status_not_overridden(self, pool, clean_operations):
"""REGRESSION TEST: Verify poller does NOT overwrite executor's 'failed' status to 'completed'.
This test catches the bug where the poller always called _mark_completed() after executor
returned, overwriting the 'failed' status that the executor had already set.
Scenario:
1. Executor catches an internal error and marks the operation as 'failed' in the DB
2. Executor returns normally (does NOT re-raise) - this is how MemoryEngine.execute_task works
3. The poller must NOT overwrite the 'failed' status to 'completed'
With the old buggy code, this test would FAIL (status would be 'completed').
"""
async def test_execute_task_fails_after_max_retries(self, pool, clean_operations):
"""Test that task is marked failed after exceeding max retries."""
from hindsight_api.worker import WorkerPoller
from hindsight_api.worker.poller import ClaimedTask
# Create a task that has already used all retries
bank_id = f"test-worker-{uuid.uuid4().hex[:8]}"
op_id = uuid.uuid4()
payload = json.dumps({"type": "test_task", "operation_id": str(op_id), "bank_id": bank_id})
await pool.execute(
"""
INSERT INTO async_operations (operation_id, bank_id, operation_type, status, task_payload, worker_id)
VALUES ($1, $2, 'test', 'processing', $3::jsonb, 'test-worker-1')
INSERT INTO async_operations (operation_id, bank_id, operation_type, status, task_payload, worker_id, retry_count)
VALUES ($1, $2, 'test', 'processing', $3::jsonb, 'test-worker-1', 3)
""",
op_id,
bank_id,
payload,
)
async def executor_that_marks_failed(task_dict):
"""Simulates MemoryEngine.execute_task behavior on internal error.
The executor catches the error, marks the operation as 'failed',
and returns normally (does NOT re-raise the exception).
"""
# Simulate internal failure handling (like MemoryEngine._mark_operation_failed)
await pool.execute(
"""
UPDATE async_operations
SET status = 'failed', error_message = $2, completed_at = now(), updated_at = now()
WHERE operation_id = $1
""",
op_id,
"Simulated conversion error: file format not supported",
)
# Returns normally - this is the key: executor does NOT re-raise
async def failing_executor(task_dict):
raise ValueError("Simulated failure")
poller = WorkerPoller(
pool=pool,
worker_id="test-worker-1",
executor=executor_that_marks_failed,
executor=failing_executor,
max_retries=3,
)
# Execute (should fail permanently) - fire-and-forget
task_dict = json.loads(payload)
claimed_task = ClaimedTask(operation_id=str(op_id), task_dict=task_dict, schema=None)
await poller.execute_task(claimed_task)
# Wait for background task to complete
completed = await poller.wait_for_active_tasks(timeout=5.0)
assert completed, "Task did not complete within timeout"
# THE KEY ASSERTION: Status must be 'failed', NOT 'completed'
# Verify task is marked as failed
row = await pool.fetchrow(
"SELECT status, error_message FROM async_operations WHERE operation_id = $1",
op_id,
)
assert row["status"] == "failed", (
f"REGRESSION: Poller overwrote executor's 'failed' status to '{row['status']}'. "
"The poller must not override status set by the executor."
)
assert "Simulated conversion error" in row["error_message"]
assert row["status"] == "failed"
assert "Max retries" in row["error_message"]
@pytest.mark.asyncio
async def test_claim_batch_skips_consolidation_when_same_bank_processing(self, pool, clean_operations):
+3 -3
View File
@@ -1,6 +1,6 @@
[package]
name = "hindsight-cli"
version = "0.4.11"
version = "0.4.10"
edition = "2021"
authors = ["Hindsight Team"]
description = "A beautiful CLI for Hindsight - semantic memory system"
@@ -20,8 +20,8 @@ clap = { version = "4.5", features = ["derive", "env"] }
# Async runtime
tokio = { version = "1", features = ["full"] }
# HTTP client (for timeout configuration and multipart file uploads)
reqwest = { version = "0.12", features = ["multipart"] }
# HTTP client (for timeout configuration)
reqwest = "0.12"
# Serialization (for config and output formatting)
serde = { version = "1.0", features = ["derive"] }
+2 -70
View File
@@ -58,16 +58,9 @@ pub struct MemoryPutResult {
pub operation_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FileRetainResult {
pub operation_ids: Vec<String>,
}
#[derive(Clone)]
pub struct ApiClient {
client: AsyncClient,
http_client: reqwest::Client,
base_url: String,
runtime: std::sync::Arc<tokio::runtime::Runtime>,
}
@@ -91,8 +84,8 @@ impl ApiClient {
let http_client = client_builder.build()?;
let client = AsyncClient::new_with_client(&base_url, http_client.clone());
Ok(ApiClient { client, http_client, base_url, runtime })
let client = AsyncClient::new_with_client(&base_url, http_client);
Ok(ApiClient { client, runtime })
}
pub fn list_agents(&self, _verbose: bool) -> Result<Vec<types::BankListItem>> {
@@ -175,67 +168,6 @@ impl ApiClient {
})
}
/// Upload files to the file retain endpoint (multipart/form-data).
/// Returns a list of operation IDs for tracking. Always async server-side.
pub fn file_retain(
&self,
bank_id: &str,
files: Vec<(String, Vec<u8>)>,
context: Option<String>,
verbose: bool,
) -> Result<FileRetainResult> {
self.runtime.block_on(async {
let url = format!("{}/v1/default/banks/{}/files/retain", self.base_url, bank_id);
let files_metadata: Vec<serde_json::Value> = files
.iter()
.map(|(name, _)| {
let mut meta = serde_json::json!({});
if let Some(ctx) = &context {
meta["context"] = serde_json::Value::String(ctx.clone());
}
// Use filename stem as document_id for deduplication
if let Some(stem) = std::path::Path::new(name)
.file_stem()
.and_then(|s| s.to_str())
{
meta["document_id"] = serde_json::Value::String(stem.to_string());
}
meta
})
.collect();
let request_json = serde_json::json!({
"files_metadata": files_metadata,
});
let mut form = reqwest::multipart::Form::new()
.text("request", request_json.to_string());
for (filename, content) in files {
let part = reqwest::multipart::Part::bytes(content)
.file_name(filename)
.mime_str("application/octet-stream")?;
form = form.part("files", part);
}
if verbose {
eprintln!("POST {}", url);
}
let response = self.http_client.post(&url).multipart(form).send().await?;
if !response.status().is_success() {
let status = response.status();
let text = response.text().await.unwrap_or_default();
anyhow::bail!("File retain failed ({}): {}", status, text);
}
let result: FileRetainResult = response.json().await?;
Ok(result)
})
}
/// Poll an operation until it completes or fails.
/// Returns Ok(true) if completed successfully, Ok(false) if failed, Err if polling error.
pub fn poll_operation(&self, agent_id: &str, operation_id: &str, verbose: bool) -> Result<(bool, Option<String>)> {
+125 -127
View File
@@ -220,23 +220,14 @@ pub fn get(
}
}
// Helper function to check if a file is supported by the file converter (markitdown)
fn is_supported_file(path: &std::path::Path) -> bool {
const SUPPORTED_EXTENSIONS: &[&str] = &[
// Documents
"pdf", "docx", "doc", "pptx", "ppt", "xlsx", "xls",
// Images (OCR)
"jpg", "jpeg", "png", "gif", "bmp", "webp", "tiff",
// Web / markup
"html", "htm",
// Text / data
"txt", "md", "csv", "json", "yaml", "yml", "toml", "xml", "rst", "adoc", "log",
// Audio (transcription)
"mp3", "wav", "ogg", "flac",
// Helper function to check if a file has a text-based extension
fn is_text_file(path: &std::path::Path) -> bool {
const TEXT_EXTENSIONS: &[&str] = &[
"txt", "md", "json", "yaml", "yml", "toml", "xml", "csv", "log", "rst", "adoc",
];
path.extension()
.and_then(|ext| ext.to_str())
.map(|ext| SUPPORTED_EXTENSIONS.contains(&ext.to_lowercase().as_str()))
.map(|ext| TEXT_EXTENSIONS.contains(&ext.to_lowercase().as_str()))
.unwrap_or(false)
}
@@ -436,10 +427,10 @@ pub fn retain_files(
anyhow::bail!("Path does not exist: {}", path.display());
}
let mut file_paths = Vec::new();
let mut files = Vec::new();
if path.is_file() {
file_paths.push(path);
files.push(path);
} else if path.is_dir() {
if recursive {
for entry in WalkDir::new(&path)
@@ -447,110 +438,133 @@ pub fn retain_files(
.filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file())
{
let file_path = entry.path();
if is_supported_file(file_path) {
file_paths.push(file_path.to_path_buf());
let path = entry.path();
if is_text_file(&path) {
files.push(path.to_path_buf());
}
}
} else {
for entry in fs::read_dir(&path)? {
let entry = entry?;
let file_path = entry.path();
if file_path.is_file() && is_supported_file(&file_path) {
file_paths.push(file_path);
let path = entry.path();
if path.is_file() && is_text_file(&path) {
files.push(path);
}
}
}
}
if file_paths.is_empty() {
ui::print_warning("No supported files found. Supported formats: pdf, docx, pptx, xlsx, jpg, png, html, txt, md, csv, mp3, wav, and more.");
if files.is_empty() {
ui::print_warning("No text files found (supported: txt, md, json, yaml, yml, toml, xml, csv, log, rst, adoc)");
return Ok(());
}
ui::print_info(&format!("Found {} file(s) to import", file_paths.len()));
ui::print_info(&format!("Found {} files to import", files.len()));
// Batch files (max 10 per request)
const BATCH_SIZE: usize = 10;
let batches: Vec<&[PathBuf]> = file_paths.chunks(BATCH_SIZE).collect();
let mut all_operation_ids: Vec<String> = Vec::new();
let pb = ui::create_progress_bar(files.len() as u64, "Processing files");
let pb = ui::create_progress_bar(file_paths.len() as u64, "Uploading files");
let mut items = Vec::new();
for batch in &batches {
let mut file_data: Vec<(String, Vec<u8>)> = Vec::new();
for file_path in *batch {
let filename = file_path
.file_name()
.and_then(|n| n.to_str())
.map(|s| s.to_string())
.unwrap_or_else(|| "file".to_string());
let content = fs::read(file_path)
.with_context(|| format!("Failed to read file: {}", file_path.display()))?;
file_data.push((filename, content));
pb.inc(1);
}
for file_path in &files {
let content = fs::read_to_string(file_path)
.with_context(|| format!("Failed to read file: {}", file_path.display()))?;
let result = client.file_retain(agent_id, file_data, context.clone(), verbose)?;
all_operation_ids.extend(result.operation_ids);
let doc_id = file_path
.file_stem()
.and_then(|s| s.to_str())
.map(|s| s.to_string())
.unwrap_or_else(config::generate_doc_id);
items.push(MemoryItem {
content,
context: context.clone(),
metadata: None,
timestamp: None,
document_id: Some(doc_id),
entities: None,
tags: None,
});
pb.inc(1);
}
pb.finish_with_message("Files uploaded");
pb.finish_with_message("Files processed");
if r#async {
if output_format == OutputFormat::Pretty {
ui::print_success("Files queued for processing");
println!(" Files: {}", file_paths.len());
for op_id in &all_operation_ids {
println!(" Operation ID: {}", op_id);
}
} else {
let result = serde_json::json!({ "operation_ids": all_operation_ids });
output::print_output(&result, output_format)?;
}
// Always use async mode for the API call
let request = RetainRequest {
items,
async_: true,
document_tags: None,
};
let spinner = if output_format == OutputFormat::Pretty {
Some(ui::create_spinner("Submitting retain request..."))
} else {
// Poll all operations until they complete
let poll_spinner = if output_format == OutputFormat::Pretty {
Some(ui::create_spinner("Processing files..."))
} else {
None
};
None
};
let mut failed = Vec::new();
for op_id in &all_operation_ids {
let (success, error_msg) = client.poll_operation(agent_id, op_id, verbose)?;
if !success {
failed.push(error_msg.unwrap_or_else(|| "Unknown error".to_string()));
}
}
let response = client.retain(agent_id, &request, true, verbose);
if let Some(mut sp) = poll_spinner {
sp.finish();
}
if let Some(mut sp) = spinner {
sp.finish();
}
if failed.is_empty() {
if output_format == OutputFormat::Pretty {
ui::print_success("Files retained successfully");
println!(" Files processed: {}", file_paths.len());
} else {
let result = serde_json::json!({
"success": true,
"files_count": file_paths.len(),
"operation_ids": all_operation_ids,
});
output::print_output(&result, output_format)?;
}
} else {
for msg in &failed {
match response {
Ok(result) => {
if r#async {
// User requested async mode - return immediately
if output_format == OutputFormat::Pretty {
ui::print_error(&format!("Retain operation failed: {}", msg));
ui::print_success("Files queued for processing");
println!(" Items: {}", result.items_count);
if let Some(op_id) = &result.operation_id {
println!(" Operation ID: {}", op_id);
}
} else {
output::print_output(&result, output_format)?;
}
} else {
// Poll until completion
if let Some(operation_id) = &result.operation_id {
let poll_spinner = if output_format == OutputFormat::Pretty {
Some(ui::create_spinner("Processing memories..."))
} else {
None
};
let (success, error_msg) = client.poll_operation(agent_id, operation_id, verbose)?;
if let Some(mut sp) = poll_spinner {
sp.finish();
}
if success {
if output_format == OutputFormat::Pretty {
ui::print_success("Files retained successfully");
println!(" Items processed: {}", result.items_count);
} else {
output::print_output(&result, output_format)?;
}
} else {
let msg = error_msg.unwrap_or_else(|| "Unknown error".to_string());
if output_format == OutputFormat::Pretty {
ui::print_error(&format!("Retain operation failed: {}", msg));
}
anyhow::bail!("Retain operation failed: {}", msg);
}
} else {
// No operation ID returned, shouldn't happen with async=true
if output_format == OutputFormat::Pretty {
ui::print_success("Files retained successfully");
println!(" Items processed: {}", result.items_count);
} else {
output::print_output(&result, output_format)?;
}
}
}
anyhow::bail!("{} operation(s) failed", failed.len());
Ok(())
}
Err(e) => Err(e)
}
Ok(())
}
pub fn delete(
@@ -665,71 +679,55 @@ mod tests {
use std::path::Path;
#[test]
fn test_is_supported_file_text_extensions() {
fn test_is_text_file_supported_extensions() {
let supported = [
"file.txt", "file.md", "file.json", "file.yaml", "file.yml",
"file.toml", "file.xml", "file.csv", "file.log", "file.rst", "file.adoc",
];
for filename in supported {
assert!(
is_supported_file(Path::new(filename)),
"{} should be recognized as a supported file",
is_text_file(Path::new(filename)),
"{} should be recognized as a text file",
filename
);
}
}
#[test]
fn test_is_supported_file_binary_extensions() {
let supported = [
"file.pdf", "file.docx", "file.pptx", "file.xlsx",
"file.png", "file.jpg", "file.jpeg", "file.gif",
"file.mp3", "file.wav",
];
for filename in supported {
assert!(
is_supported_file(Path::new(filename)),
"{} should be recognized as a supported file",
filename
);
}
fn test_is_text_file_case_insensitive() {
assert!(is_text_file(Path::new("file.JSON")));
assert!(is_text_file(Path::new("file.TXT")));
assert!(is_text_file(Path::new("file.Md")));
assert!(is_text_file(Path::new("file.YAML")));
}
#[test]
fn test_is_supported_file_case_insensitive() {
assert!(is_supported_file(Path::new("file.JSON")));
assert!(is_supported_file(Path::new("file.TXT")));
assert!(is_supported_file(Path::new("file.Md")));
assert!(is_supported_file(Path::new("file.YAML")));
assert!(is_supported_file(Path::new("file.PDF")));
}
#[test]
fn test_is_supported_file_unsupported_extensions() {
fn test_is_text_file_unsupported_extensions() {
let unsupported = [
"file.pdf", "file.doc", "file.docx", "file.png", "file.jpg",
"file.exe", "file.bin", "file.zip", "file.tar", "file.gz",
];
for filename in unsupported {
assert!(
!is_supported_file(Path::new(filename)),
"{} should NOT be recognized as a supported file",
!is_text_file(Path::new(filename)),
"{} should NOT be recognized as a text file",
filename
);
}
}
#[test]
fn test_is_supported_file_no_extension() {
assert!(!is_supported_file(Path::new("README")));
assert!(!is_supported_file(Path::new("Makefile")));
assert!(!is_supported_file(Path::new(".gitignore")));
fn test_is_text_file_no_extension() {
assert!(!is_text_file(Path::new("README")));
assert!(!is_text_file(Path::new("Makefile")));
assert!(!is_text_file(Path::new(".gitignore")));
}
#[test]
fn test_is_supported_file_with_path() {
assert!(is_supported_file(Path::new("/some/path/to/file.json")));
assert!(is_supported_file(Path::new("../relative/path/file.md")));
assert!(is_supported_file(Path::new("/path/to/image.png")));
fn test_is_text_file_with_path() {
assert!(is_text_file(Path::new("/some/path/to/file.json")));
assert!(is_text_file(Path::new("../relative/path/file.md")));
assert!(!is_text_file(Path::new("/path/to/image.png")));
}
#[test]
-24
View File
@@ -1,24 +0,0 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
-226
View File
@@ -1,226 +0,0 @@
# Go API client for hindsight
HTTP API for Hindsight
## Overview
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client.
- API version: 0.4.11
- Package version: 1.0.0
- Generator version: 7.10.0
- Build package: org.openapitools.codegen.languages.GoClientCodegen
## Installation
Install the following dependencies:
```sh
go get github.com/stretchr/testify/assert
go get golang.org/x/net/context
```
Put the package under your project folder and add the following in import:
```go
import hindsight "github.com/vectorize-io/hindsight/hindsight-clients/go"
```
To use a proxy, set the environment variable `HTTP_PROXY`:
```go
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
```
## Configuration of Server URL
Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification.
### Select Server Configuration
For using other server than the one defined on index 0 set context value `hindsight.ContextServerIndex` of type `int`.
```go
ctx := context.WithValue(context.Background(), hindsight.ContextServerIndex, 1)
```
### Templated Server URL
Templated server URL is formatted using default variables from configuration or from context value `hindsight.ContextServerVariables` of type `map[string]string`.
```go
ctx := context.WithValue(context.Background(), hindsight.ContextServerVariables, map[string]string{
"basePath": "v2",
})
```
Note, enum values are always validated and all unused variables are silently ignored.
### URLs Configuration per Operation
Each operation can use different server URL defined using `OperationServers` map in the `Configuration`.
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
Similar rules for overriding default operation server index and variables applies by using `hindsight.ContextOperationServerIndices` and `hindsight.ContextOperationServerVariables` context maps.
```go
ctx := context.WithValue(context.Background(), hindsight.ContextOperationServerIndices, map[string]int{
"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), hindsight.ContextOperationServerVariables, map[string]map[string]string{
"{classname}Service.{nickname}": {
"port": "8443",
},
})
```
## Documentation for API Endpoints
All URIs are relative to *http://localhost*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*BanksAPI* | [**AddBankBackground**](docs/BanksAPI.md#addbankbackground) | **Post** /v1/default/banks/{bank_id}/background | Add/merge memory bank background (deprecated)
*BanksAPI* | [**ClearObservations**](docs/BanksAPI.md#clearobservations) | **Delete** /v1/default/banks/{bank_id}/observations | Clear all observations
*BanksAPI* | [**CreateOrUpdateBank**](docs/BanksAPI.md#createorupdatebank) | **Put** /v1/default/banks/{bank_id} | Create or update memory bank
*BanksAPI* | [**DeleteBank**](docs/BanksAPI.md#deletebank) | **Delete** /v1/default/banks/{bank_id} | Delete memory bank
*BanksAPI* | [**GetAgentStats**](docs/BanksAPI.md#getagentstats) | **Get** /v1/default/banks/{bank_id}/stats | Get statistics for memory bank
*BanksAPI* | [**GetBankConfig**](docs/BanksAPI.md#getbankconfig) | **Get** /v1/default/banks/{bank_id}/config | Get bank configuration
*BanksAPI* | [**GetBankProfile**](docs/BanksAPI.md#getbankprofile) | **Get** /v1/default/banks/{bank_id}/profile | Get memory bank profile
*BanksAPI* | [**ListBanks**](docs/BanksAPI.md#listbanks) | **Get** /v1/default/banks | List all memory banks
*BanksAPI* | [**ResetBankConfig**](docs/BanksAPI.md#resetbankconfig) | **Delete** /v1/default/banks/{bank_id}/config | Reset bank configuration
*BanksAPI* | [**TriggerConsolidation**](docs/BanksAPI.md#triggerconsolidation) | **Post** /v1/default/banks/{bank_id}/consolidate | Trigger consolidation
*BanksAPI* | [**UpdateBank**](docs/BanksAPI.md#updatebank) | **Patch** /v1/default/banks/{bank_id} | Partial update memory bank
*BanksAPI* | [**UpdateBankConfig**](docs/BanksAPI.md#updatebankconfig) | **Patch** /v1/default/banks/{bank_id}/config | Update bank configuration
*BanksAPI* | [**UpdateBankDisposition**](docs/BanksAPI.md#updatebankdisposition) | **Put** /v1/default/banks/{bank_id}/profile | Update memory bank disposition
*DirectivesAPI* | [**CreateDirective**](docs/DirectivesAPI.md#createdirective) | **Post** /v1/default/banks/{bank_id}/directives | Create directive
*DirectivesAPI* | [**DeleteDirective**](docs/DirectivesAPI.md#deletedirective) | **Delete** /v1/default/banks/{bank_id}/directives/{directive_id} | Delete directive
*DirectivesAPI* | [**GetDirective**](docs/DirectivesAPI.md#getdirective) | **Get** /v1/default/banks/{bank_id}/directives/{directive_id} | Get directive
*DirectivesAPI* | [**ListDirectives**](docs/DirectivesAPI.md#listdirectives) | **Get** /v1/default/banks/{bank_id}/directives | List directives
*DirectivesAPI* | [**UpdateDirective**](docs/DirectivesAPI.md#updatedirective) | **Patch** /v1/default/banks/{bank_id}/directives/{directive_id} | Update directive
*DocumentsAPI* | [**DeleteDocument**](docs/DocumentsAPI.md#deletedocument) | **Delete** /v1/default/banks/{bank_id}/documents/{document_id} | Delete a document
*DocumentsAPI* | [**GetChunk**](docs/DocumentsAPI.md#getchunk) | **Get** /v1/default/chunks/{chunk_id} | Get chunk details
*DocumentsAPI* | [**GetDocument**](docs/DocumentsAPI.md#getdocument) | **Get** /v1/default/banks/{bank_id}/documents/{document_id} | Get document details
*DocumentsAPI* | [**ListDocuments**](docs/DocumentsAPI.md#listdocuments) | **Get** /v1/default/banks/{bank_id}/documents | List documents
*EntitiesAPI* | [**GetEntity**](docs/EntitiesAPI.md#getentity) | **Get** /v1/default/banks/{bank_id}/entities/{entity_id} | Get entity details
*EntitiesAPI* | [**ListEntities**](docs/EntitiesAPI.md#listentities) | **Get** /v1/default/banks/{bank_id}/entities | List entities
*EntitiesAPI* | [**RegenerateEntityObservations**](docs/EntitiesAPI.md#regenerateentityobservations) | **Post** /v1/default/banks/{bank_id}/entities/{entity_id}/regenerate | Regenerate entity observations (deprecated)
*MemoryAPI* | [**ClearBankMemories**](docs/MemoryAPI.md#clearbankmemories) | **Delete** /v1/default/banks/{bank_id}/memories | Clear memory bank memories
*MemoryAPI* | [**GetGraph**](docs/MemoryAPI.md#getgraph) | **Get** /v1/default/banks/{bank_id}/graph | Get memory graph data
*MemoryAPI* | [**GetMemory**](docs/MemoryAPI.md#getmemory) | **Get** /v1/default/banks/{bank_id}/memories/{memory_id} | Get memory unit
*MemoryAPI* | [**ListMemories**](docs/MemoryAPI.md#listmemories) | **Get** /v1/default/banks/{bank_id}/memories/list | List memory units
*MemoryAPI* | [**ListTags**](docs/MemoryAPI.md#listtags) | **Get** /v1/default/banks/{bank_id}/tags | List tags
*MemoryAPI* | [**RecallMemories**](docs/MemoryAPI.md#recallmemories) | **Post** /v1/default/banks/{bank_id}/memories/recall | Recall memory
*MemoryAPI* | [**Reflect**](docs/MemoryAPI.md#reflect) | **Post** /v1/default/banks/{bank_id}/reflect | Reflect and generate answer
*MemoryAPI* | [**RetainMemories**](docs/MemoryAPI.md#retainmemories) | **Post** /v1/default/banks/{bank_id}/memories | Retain memories
*MentalModelsAPI* | [**CreateMentalModel**](docs/MentalModelsAPI.md#creatementalmodel) | **Post** /v1/default/banks/{bank_id}/mental-models | Create mental model
*MentalModelsAPI* | [**DeleteMentalModel**](docs/MentalModelsAPI.md#deletementalmodel) | **Delete** /v1/default/banks/{bank_id}/mental-models/{mental_model_id} | Delete mental model
*MentalModelsAPI* | [**GetMentalModel**](docs/MentalModelsAPI.md#getmentalmodel) | **Get** /v1/default/banks/{bank_id}/mental-models/{mental_model_id} | Get mental model
*MentalModelsAPI* | [**ListMentalModels**](docs/MentalModelsAPI.md#listmentalmodels) | **Get** /v1/default/banks/{bank_id}/mental-models | List mental models
*MentalModelsAPI* | [**RefreshMentalModel**](docs/MentalModelsAPI.md#refreshmentalmodel) | **Post** /v1/default/banks/{bank_id}/mental-models/{mental_model_id}/refresh | Refresh mental model
*MentalModelsAPI* | [**UpdateMentalModel**](docs/MentalModelsAPI.md#updatementalmodel) | **Patch** /v1/default/banks/{bank_id}/mental-models/{mental_model_id} | Update mental model
*MonitoringAPI* | [**GetVersion**](docs/MonitoringAPI.md#getversion) | **Get** /version | Get API version and feature flags
*MonitoringAPI* | [**HealthEndpointHealthGet**](docs/MonitoringAPI.md#healthendpointhealthget) | **Get** /health | Health check endpoint
*MonitoringAPI* | [**MetricsEndpointMetricsGet**](docs/MonitoringAPI.md#metricsendpointmetricsget) | **Get** /metrics | Prometheus metrics endpoint
*OperationsAPI* | [**CancelOperation**](docs/OperationsAPI.md#canceloperation) | **Delete** /v1/default/banks/{bank_id}/operations/{operation_id} | Cancel a pending async operation
*OperationsAPI* | [**GetOperationStatus**](docs/OperationsAPI.md#getoperationstatus) | **Get** /v1/default/banks/{bank_id}/operations/{operation_id} | Get operation status
*OperationsAPI* | [**ListOperations**](docs/OperationsAPI.md#listoperations) | **Get** /v1/default/banks/{bank_id}/operations | List async operations
## Documentation For Models
- [AddBackgroundRequest](docs/AddBackgroundRequest.md)
- [AsyncOperationSubmitResponse](docs/AsyncOperationSubmitResponse.md)
- [BackgroundResponse](docs/BackgroundResponse.md)
- [BankConfigResponse](docs/BankConfigResponse.md)
- [BankConfigUpdate](docs/BankConfigUpdate.md)
- [BankListItem](docs/BankListItem.md)
- [BankListResponse](docs/BankListResponse.md)
- [BankProfileResponse](docs/BankProfileResponse.md)
- [BankStatsResponse](docs/BankStatsResponse.md)
- [Budget](docs/Budget.md)
- [CancelOperationResponse](docs/CancelOperationResponse.md)
- [ChunkData](docs/ChunkData.md)
- [ChunkIncludeOptions](docs/ChunkIncludeOptions.md)
- [ChunkResponse](docs/ChunkResponse.md)
- [ConsolidationResponse](docs/ConsolidationResponse.md)
- [CreateBankRequest](docs/CreateBankRequest.md)
- [CreateDirectiveRequest](docs/CreateDirectiveRequest.md)
- [CreateMentalModelRequest](docs/CreateMentalModelRequest.md)
- [CreateMentalModelResponse](docs/CreateMentalModelResponse.md)
- [DeleteDocumentResponse](docs/DeleteDocumentResponse.md)
- [DeleteResponse](docs/DeleteResponse.md)
- [DirectiveListResponse](docs/DirectiveListResponse.md)
- [DirectiveResponse](docs/DirectiveResponse.md)
- [DispositionTraits](docs/DispositionTraits.md)
- [DocumentResponse](docs/DocumentResponse.md)
- [EntityDetailResponse](docs/EntityDetailResponse.md)
- [EntityIncludeOptions](docs/EntityIncludeOptions.md)
- [EntityInput](docs/EntityInput.md)
- [EntityListItem](docs/EntityListItem.md)
- [EntityListResponse](docs/EntityListResponse.md)
- [EntityObservationResponse](docs/EntityObservationResponse.md)
- [EntityStateResponse](docs/EntityStateResponse.md)
- [FeaturesInfo](docs/FeaturesInfo.md)
- [GraphDataResponse](docs/GraphDataResponse.md)
- [HTTPValidationError](docs/HTTPValidationError.md)
- [IncludeOptions](docs/IncludeOptions.md)
- [ListDocumentsResponse](docs/ListDocumentsResponse.md)
- [ListMemoryUnitsResponse](docs/ListMemoryUnitsResponse.md)
- [ListTagsResponse](docs/ListTagsResponse.md)
- [MemoryItem](docs/MemoryItem.md)
- [MentalModelListResponse](docs/MentalModelListResponse.md)
- [MentalModelResponse](docs/MentalModelResponse.md)
- [MentalModelTrigger](docs/MentalModelTrigger.md)
- [OperationResponse](docs/OperationResponse.md)
- [OperationStatusResponse](docs/OperationStatusResponse.md)
- [OperationsListResponse](docs/OperationsListResponse.md)
- [RecallRequest](docs/RecallRequest.md)
- [RecallResponse](docs/RecallResponse.md)
- [RecallResult](docs/RecallResult.md)
- [ReflectBasedOn](docs/ReflectBasedOn.md)
- [ReflectDirective](docs/ReflectDirective.md)
- [ReflectFact](docs/ReflectFact.md)
- [ReflectIncludeOptions](docs/ReflectIncludeOptions.md)
- [ReflectLLMCall](docs/ReflectLLMCall.md)
- [ReflectMentalModel](docs/ReflectMentalModel.md)
- [ReflectRequest](docs/ReflectRequest.md)
- [ReflectResponse](docs/ReflectResponse.md)
- [ReflectToolCall](docs/ReflectToolCall.md)
- [ReflectTrace](docs/ReflectTrace.md)
- [RetainRequest](docs/RetainRequest.md)
- [RetainResponse](docs/RetainResponse.md)
- [TagItem](docs/TagItem.md)
- [TokenUsage](docs/TokenUsage.md)
- [ToolCallsIncludeOptions](docs/ToolCallsIncludeOptions.md)
- [UpdateDirectiveRequest](docs/UpdateDirectiveRequest.md)
- [UpdateDispositionRequest](docs/UpdateDispositionRequest.md)
- [UpdateMentalModelRequest](docs/UpdateMentalModelRequest.md)
- [ValidationError](docs/ValidationError.md)
- [ValidationErrorLocInner](docs/ValidationErrorLocInner.md)
- [VersionResponse](docs/VersionResponse.md)
## Documentation For Authorization
Endpoints do not require authorization.
## Documentation for Utility Methods
Due to the fact that model structure members are all pointers, this package contains
a number of utility functions to easily obtain pointers to values of basic types.
Each of these functions takes a value of the given basic type and returns a pointer to it:
* `PtrBool`
* `PtrInt`
* `PtrInt32`
* `PtrInt64`
* `PtrFloat`
* `PtrFloat32`
* `PtrFloat64`
* `PtrString`
* `PtrTime`
## Author
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-737
View File
@@ -1,737 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
"strings"
"reflect"
)
// DirectivesAPIService DirectivesAPI service
type DirectivesAPIService service
type ApiCreateDirectiveRequest struct {
ctx context.Context
ApiService *DirectivesAPIService
bankId string
createDirectiveRequest *CreateDirectiveRequest
authorization *string
}
func (r ApiCreateDirectiveRequest) CreateDirectiveRequest(createDirectiveRequest CreateDirectiveRequest) ApiCreateDirectiveRequest {
r.createDirectiveRequest = &createDirectiveRequest
return r
}
func (r ApiCreateDirectiveRequest) Authorization(authorization string) ApiCreateDirectiveRequest {
r.authorization = &authorization
return r
}
func (r ApiCreateDirectiveRequest) Execute() (*DirectiveResponse, *http.Response, error) {
return r.ApiService.CreateDirectiveExecute(r)
}
/*
CreateDirective Create directive
Create a hard rule that will be injected into prompts.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@return ApiCreateDirectiveRequest
*/
func (a *DirectivesAPIService) CreateDirective(ctx context.Context, bankId string) ApiCreateDirectiveRequest {
return ApiCreateDirectiveRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
}
}
// Execute executes the request
// @return DirectiveResponse
func (a *DirectivesAPIService) CreateDirectiveExecute(r ApiCreateDirectiveRequest) (*DirectiveResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPost
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *DirectiveResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DirectivesAPIService.CreateDirective")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/directives"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.createDirectiveRequest == nil {
return localVarReturnValue, nil, reportError("createDirectiveRequest is required and must be specified")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"application/json"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
// body params
localVarPostBody = r.createDirectiveRequest
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiDeleteDirectiveRequest struct {
ctx context.Context
ApiService *DirectivesAPIService
bankId string
directiveId string
authorization *string
}
func (r ApiDeleteDirectiveRequest) Authorization(authorization string) ApiDeleteDirectiveRequest {
r.authorization = &authorization
return r
}
func (r ApiDeleteDirectiveRequest) Execute() (interface{}, *http.Response, error) {
return r.ApiService.DeleteDirectiveExecute(r)
}
/*
DeleteDirective Delete directive
Delete a directive.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param directiveId
@return ApiDeleteDirectiveRequest
*/
func (a *DirectivesAPIService) DeleteDirective(ctx context.Context, bankId string, directiveId string) ApiDeleteDirectiveRequest {
return ApiDeleteDirectiveRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
directiveId: directiveId,
}
}
// Execute executes the request
// @return interface{}
func (a *DirectivesAPIService) DeleteDirectiveExecute(r ApiDeleteDirectiveRequest) (interface{}, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodDelete
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue interface{}
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DirectivesAPIService.DeleteDirective")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/directives/{directive_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"directive_id"+"}", url.PathEscape(parameterValueToString(r.directiveId, "directiveId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiGetDirectiveRequest struct {
ctx context.Context
ApiService *DirectivesAPIService
bankId string
directiveId string
authorization *string
}
func (r ApiGetDirectiveRequest) Authorization(authorization string) ApiGetDirectiveRequest {
r.authorization = &authorization
return r
}
func (r ApiGetDirectiveRequest) Execute() (*DirectiveResponse, *http.Response, error) {
return r.ApiService.GetDirectiveExecute(r)
}
/*
GetDirective Get directive
Get a specific directive by ID.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param directiveId
@return ApiGetDirectiveRequest
*/
func (a *DirectivesAPIService) GetDirective(ctx context.Context, bankId string, directiveId string) ApiGetDirectiveRequest {
return ApiGetDirectiveRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
directiveId: directiveId,
}
}
// Execute executes the request
// @return DirectiveResponse
func (a *DirectivesAPIService) GetDirectiveExecute(r ApiGetDirectiveRequest) (*DirectiveResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *DirectiveResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DirectivesAPIService.GetDirective")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/directives/{directive_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"directive_id"+"}", url.PathEscape(parameterValueToString(r.directiveId, "directiveId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiListDirectivesRequest struct {
ctx context.Context
ApiService *DirectivesAPIService
bankId string
tags *[]string
tagsMatch *string
activeOnly *bool
limit *int32
offset *int32
authorization *string
}
// Filter by tags
func (r ApiListDirectivesRequest) Tags(tags []string) ApiListDirectivesRequest {
r.tags = &tags
return r
}
// How to match tags
func (r ApiListDirectivesRequest) TagsMatch(tagsMatch string) ApiListDirectivesRequest {
r.tagsMatch = &tagsMatch
return r
}
// Only return active directives
func (r ApiListDirectivesRequest) ActiveOnly(activeOnly bool) ApiListDirectivesRequest {
r.activeOnly = &activeOnly
return r
}
func (r ApiListDirectivesRequest) Limit(limit int32) ApiListDirectivesRequest {
r.limit = &limit
return r
}
func (r ApiListDirectivesRequest) Offset(offset int32) ApiListDirectivesRequest {
r.offset = &offset
return r
}
func (r ApiListDirectivesRequest) Authorization(authorization string) ApiListDirectivesRequest {
r.authorization = &authorization
return r
}
func (r ApiListDirectivesRequest) Execute() (*DirectiveListResponse, *http.Response, error) {
return r.ApiService.ListDirectivesExecute(r)
}
/*
ListDirectives List directives
List hard rules that are injected into prompts.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@return ApiListDirectivesRequest
*/
func (a *DirectivesAPIService) ListDirectives(ctx context.Context, bankId string) ApiListDirectivesRequest {
return ApiListDirectivesRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
}
}
// Execute executes the request
// @return DirectiveListResponse
func (a *DirectivesAPIService) ListDirectivesExecute(r ApiListDirectivesRequest) (*DirectiveListResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *DirectiveListResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DirectivesAPIService.ListDirectives")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/directives"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.tags != nil {
t := *r.tags
if reflect.TypeOf(t).Kind() == reflect.Slice {
s := reflect.ValueOf(t)
for i := 0; i < s.Len(); i++ {
parameterAddToHeaderOrQuery(localVarQueryParams, "tags", s.Index(i).Interface(), "form", "multi")
}
} else {
parameterAddToHeaderOrQuery(localVarQueryParams, "tags", t, "form", "multi")
}
}
if r.tagsMatch != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "tags_match", r.tagsMatch, "form", "")
} else {
var defaultValue string = "any"
r.tagsMatch = &defaultValue
}
if r.activeOnly != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "active_only", r.activeOnly, "form", "")
} else {
var defaultValue bool = true
r.activeOnly = &defaultValue
}
if r.limit != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "form", "")
} else {
var defaultValue int32 = 100
r.limit = &defaultValue
}
if r.offset != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "form", "")
} else {
var defaultValue int32 = 0
r.offset = &defaultValue
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiUpdateDirectiveRequest struct {
ctx context.Context
ApiService *DirectivesAPIService
bankId string
directiveId string
updateDirectiveRequest *UpdateDirectiveRequest
authorization *string
}
func (r ApiUpdateDirectiveRequest) UpdateDirectiveRequest(updateDirectiveRequest UpdateDirectiveRequest) ApiUpdateDirectiveRequest {
r.updateDirectiveRequest = &updateDirectiveRequest
return r
}
func (r ApiUpdateDirectiveRequest) Authorization(authorization string) ApiUpdateDirectiveRequest {
r.authorization = &authorization
return r
}
func (r ApiUpdateDirectiveRequest) Execute() (*DirectiveResponse, *http.Response, error) {
return r.ApiService.UpdateDirectiveExecute(r)
}
/*
UpdateDirective Update directive
Update a directive's properties.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param directiveId
@return ApiUpdateDirectiveRequest
*/
func (a *DirectivesAPIService) UpdateDirective(ctx context.Context, bankId string, directiveId string) ApiUpdateDirectiveRequest {
return ApiUpdateDirectiveRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
directiveId: directiveId,
}
}
// Execute executes the request
// @return DirectiveResponse
func (a *DirectivesAPIService) UpdateDirectiveExecute(r ApiUpdateDirectiveRequest) (*DirectiveResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPatch
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *DirectiveResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DirectivesAPIService.UpdateDirective")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/directives/{directive_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"directive_id"+"}", url.PathEscape(parameterValueToString(r.directiveId, "directiveId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.updateDirectiveRequest == nil {
return localVarReturnValue, nil, reportError("updateDirectiveRequest is required and must be specified")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"application/json"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
// body params
localVarPostBody = r.updateDirectiveRequest
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
-560
View File
@@ -1,560 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
"strings"
)
// DocumentsAPIService DocumentsAPI service
type DocumentsAPIService service
type ApiDeleteDocumentRequest struct {
ctx context.Context
ApiService *DocumentsAPIService
bankId string
documentId string
authorization *string
}
func (r ApiDeleteDocumentRequest) Authorization(authorization string) ApiDeleteDocumentRequest {
r.authorization = &authorization
return r
}
func (r ApiDeleteDocumentRequest) Execute() (*DeleteDocumentResponse, *http.Response, error) {
return r.ApiService.DeleteDocumentExecute(r)
}
/*
DeleteDocument Delete a document
Delete a document and all its associated memory units and links.
This will cascade delete:
- The document itself
- All memory units extracted from this document
- All links (temporal, semantic, entity) associated with those memory units
This operation cannot be undone.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param documentId
@return ApiDeleteDocumentRequest
*/
func (a *DocumentsAPIService) DeleteDocument(ctx context.Context, bankId string, documentId string) ApiDeleteDocumentRequest {
return ApiDeleteDocumentRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
documentId: documentId,
}
}
// Execute executes the request
// @return DeleteDocumentResponse
func (a *DocumentsAPIService) DeleteDocumentExecute(r ApiDeleteDocumentRequest) (*DeleteDocumentResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodDelete
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *DeleteDocumentResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DocumentsAPIService.DeleteDocument")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/documents/{document_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"document_id"+"}", url.PathEscape(parameterValueToString(r.documentId, "documentId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiGetChunkRequest struct {
ctx context.Context
ApiService *DocumentsAPIService
chunkId string
authorization *string
}
func (r ApiGetChunkRequest) Authorization(authorization string) ApiGetChunkRequest {
r.authorization = &authorization
return r
}
func (r ApiGetChunkRequest) Execute() (*ChunkResponse, *http.Response, error) {
return r.ApiService.GetChunkExecute(r)
}
/*
GetChunk Get chunk details
Get a specific chunk by its ID
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param chunkId
@return ApiGetChunkRequest
*/
func (a *DocumentsAPIService) GetChunk(ctx context.Context, chunkId string) ApiGetChunkRequest {
return ApiGetChunkRequest{
ApiService: a,
ctx: ctx,
chunkId: chunkId,
}
}
// Execute executes the request
// @return ChunkResponse
func (a *DocumentsAPIService) GetChunkExecute(r ApiGetChunkRequest) (*ChunkResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *ChunkResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DocumentsAPIService.GetChunk")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/chunks/{chunk_id}"
localVarPath = strings.Replace(localVarPath, "{"+"chunk_id"+"}", url.PathEscape(parameterValueToString(r.chunkId, "chunkId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiGetDocumentRequest struct {
ctx context.Context
ApiService *DocumentsAPIService
bankId string
documentId string
authorization *string
}
func (r ApiGetDocumentRequest) Authorization(authorization string) ApiGetDocumentRequest {
r.authorization = &authorization
return r
}
func (r ApiGetDocumentRequest) Execute() (*DocumentResponse, *http.Response, error) {
return r.ApiService.GetDocumentExecute(r)
}
/*
GetDocument Get document details
Get a specific document including its original text
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param documentId
@return ApiGetDocumentRequest
*/
func (a *DocumentsAPIService) GetDocument(ctx context.Context, bankId string, documentId string) ApiGetDocumentRequest {
return ApiGetDocumentRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
documentId: documentId,
}
}
// Execute executes the request
// @return DocumentResponse
func (a *DocumentsAPIService) GetDocumentExecute(r ApiGetDocumentRequest) (*DocumentResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *DocumentResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DocumentsAPIService.GetDocument")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/documents/{document_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"document_id"+"}", url.PathEscape(parameterValueToString(r.documentId, "documentId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiListDocumentsRequest struct {
ctx context.Context
ApiService *DocumentsAPIService
bankId string
q *string
limit *int32
offset *int32
authorization *string
}
func (r ApiListDocumentsRequest) Q(q string) ApiListDocumentsRequest {
r.q = &q
return r
}
func (r ApiListDocumentsRequest) Limit(limit int32) ApiListDocumentsRequest {
r.limit = &limit
return r
}
func (r ApiListDocumentsRequest) Offset(offset int32) ApiListDocumentsRequest {
r.offset = &offset
return r
}
func (r ApiListDocumentsRequest) Authorization(authorization string) ApiListDocumentsRequest {
r.authorization = &authorization
return r
}
func (r ApiListDocumentsRequest) Execute() (*ListDocumentsResponse, *http.Response, error) {
return r.ApiService.ListDocumentsExecute(r)
}
/*
ListDocuments List documents
List documents with pagination and optional search. Documents are the source content from which memory units are extracted.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@return ApiListDocumentsRequest
*/
func (a *DocumentsAPIService) ListDocuments(ctx context.Context, bankId string) ApiListDocumentsRequest {
return ApiListDocumentsRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
}
}
// Execute executes the request
// @return ListDocumentsResponse
func (a *DocumentsAPIService) ListDocumentsExecute(r ApiListDocumentsRequest) (*ListDocumentsResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *ListDocumentsResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DocumentsAPIService.ListDocuments")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/documents"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.q != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "q", r.q, "form", "")
}
if r.limit != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "form", "")
} else {
var defaultValue int32 = 100
r.limit = &defaultValue
}
if r.offset != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "form", "")
} else {
var defaultValue int32 = 0
r.offset = &defaultValue
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
-427
View File
@@ -1,427 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
"strings"
)
// EntitiesAPIService EntitiesAPI service
type EntitiesAPIService service
type ApiGetEntityRequest struct {
ctx context.Context
ApiService *EntitiesAPIService
bankId string
entityId string
authorization *string
}
func (r ApiGetEntityRequest) Authorization(authorization string) ApiGetEntityRequest {
r.authorization = &authorization
return r
}
func (r ApiGetEntityRequest) Execute() (*EntityDetailResponse, *http.Response, error) {
return r.ApiService.GetEntityExecute(r)
}
/*
GetEntity Get entity details
Get detailed information about an entity including observations (mental model).
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param entityId
@return ApiGetEntityRequest
*/
func (a *EntitiesAPIService) GetEntity(ctx context.Context, bankId string, entityId string) ApiGetEntityRequest {
return ApiGetEntityRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
entityId: entityId,
}
}
// Execute executes the request
// @return EntityDetailResponse
func (a *EntitiesAPIService) GetEntityExecute(r ApiGetEntityRequest) (*EntityDetailResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *EntityDetailResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "EntitiesAPIService.GetEntity")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/entities/{entity_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"entity_id"+"}", url.PathEscape(parameterValueToString(r.entityId, "entityId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiListEntitiesRequest struct {
ctx context.Context
ApiService *EntitiesAPIService
bankId string
limit *int32
offset *int32
authorization *string
}
// Maximum number of entities to return
func (r ApiListEntitiesRequest) Limit(limit int32) ApiListEntitiesRequest {
r.limit = &limit
return r
}
// Offset for pagination
func (r ApiListEntitiesRequest) Offset(offset int32) ApiListEntitiesRequest {
r.offset = &offset
return r
}
func (r ApiListEntitiesRequest) Authorization(authorization string) ApiListEntitiesRequest {
r.authorization = &authorization
return r
}
func (r ApiListEntitiesRequest) Execute() (*EntityListResponse, *http.Response, error) {
return r.ApiService.ListEntitiesExecute(r)
}
/*
ListEntities List entities
List all entities (people, organizations, etc.) known by the bank, ordered by mention count. Supports pagination.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@return ApiListEntitiesRequest
*/
func (a *EntitiesAPIService) ListEntities(ctx context.Context, bankId string) ApiListEntitiesRequest {
return ApiListEntitiesRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
}
}
// Execute executes the request
// @return EntityListResponse
func (a *EntitiesAPIService) ListEntitiesExecute(r ApiListEntitiesRequest) (*EntityListResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *EntityListResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "EntitiesAPIService.ListEntities")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/entities"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.limit != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "form", "")
} else {
var defaultValue int32 = 100
r.limit = &defaultValue
}
if r.offset != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "form", "")
} else {
var defaultValue int32 = 0
r.offset = &defaultValue
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiRegenerateEntityObservationsRequest struct {
ctx context.Context
ApiService *EntitiesAPIService
bankId string
entityId string
authorization *string
}
func (r ApiRegenerateEntityObservationsRequest) Authorization(authorization string) ApiRegenerateEntityObservationsRequest {
r.authorization = &authorization
return r
}
func (r ApiRegenerateEntityObservationsRequest) Execute() (*EntityDetailResponse, *http.Response, error) {
return r.ApiService.RegenerateEntityObservationsExecute(r)
}
/*
RegenerateEntityObservations Regenerate entity observations (deprecated)
This endpoint is deprecated. Entity observations have been replaced by mental models.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param entityId
@return ApiRegenerateEntityObservationsRequest
Deprecated
*/
func (a *EntitiesAPIService) RegenerateEntityObservations(ctx context.Context, bankId string, entityId string) ApiRegenerateEntityObservationsRequest {
return ApiRegenerateEntityObservationsRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
entityId: entityId,
}
}
// Execute executes the request
// @return EntityDetailResponse
// Deprecated
func (a *EntitiesAPIService) RegenerateEntityObservationsExecute(r ApiRegenerateEntityObservationsRequest) (*EntityDetailResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPost
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *EntityDetailResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "EntitiesAPIService.RegenerateEntityObservations")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/entities/{entity_id}/regenerate"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"entity_id"+"}", url.PathEscape(parameterValueToString(r.entityId, "entityId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
-209
View File
@@ -1,209 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
"os"
"strings"
)
// FilesAPIService FilesAPI service
type FilesAPIService service
type ApiFileRetainRequest struct {
ctx context.Context
ApiService *FilesAPIService
bankId string
files []*os.File
request *string
authorization *string
}
// Files to upload and convert
func (r ApiFileRetainRequest) Files(files []*os.File) ApiFileRetainRequest {
r.files = files
return r
}
// JSON string with FileRetainRequest model
func (r ApiFileRetainRequest) Request(request string) ApiFileRetainRequest {
r.request = &request
return r
}
func (r ApiFileRetainRequest) Authorization(authorization string) ApiFileRetainRequest {
r.authorization = &authorization
return r
}
func (r ApiFileRetainRequest) Execute() (*FileRetainResponse, *http.Response, error) {
return r.ApiService.FileRetainExecute(r)
}
/*
FileRetain Convert files to memories
Upload files (PDF, DOCX, etc.), convert them to markdown, and retain as memories.
This endpoint handles file upload, conversion, and memory creation in a single operation.
**Features:**
- Supports PDF, DOCX, PPTX, XLSX, images (with OCR), audio (with transcription)
- Automatic file-to-markdown conversion using pluggable parsers
- Files stored in object storage (PostgreSQL by default, S3 for production)
- Each file becomes a separate document with optional metadata/tags
- Always processes asynchronously returns operation IDs immediately
**The system automatically:**
1. Stores uploaded files in object storage
2. Converts files to markdown
3. Creates document records with file metadata
4. Extracts facts and creates memory units (same as regular retain)
Use the operations endpoint to monitor progress.
**Request format:** multipart/form-data with:
- `files`: One or more files to upload
- `request`: JSON string with FileRetainRequest model (files_metadata)
**Note:** File parser is configured server-side via `HINDSIGHT_API_FILE_PARSER` (default: markitdown).
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@return ApiFileRetainRequest
*/
func (a *FilesAPIService) FileRetain(ctx context.Context, bankId string) ApiFileRetainRequest {
return ApiFileRetainRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
}
}
// Execute executes the request
// @return FileRetainResponse
func (a *FilesAPIService) FileRetainExecute(r ApiFileRetainRequest) (*FileRetainResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPost
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *FileRetainResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "FilesAPIService.FileRetain")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/files/retain"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.files == nil {
return localVarReturnValue, nil, reportError("files is required and must be specified")
}
if r.request == nil {
return localVarReturnValue, nil, reportError("request is required and must be specified")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"multipart/form-data"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
var filesLocalVarFormFileName string
var filesLocalVarFileName string
var filesLocalVarFileBytes []byte
filesLocalVarFormFileName = "files"
filesLocalVarFile := r.files
if filesLocalVarFile != nil {
// loop through the array to prepare multiple files upload
for _, filesLocalVarFileValue := range filesLocalVarFile {
fbs, _ := io.ReadAll(filesLocalVarFileValue)
filesLocalVarFileBytes = fbs
filesLocalVarFileName = filesLocalVarFileValue.Name()
filesLocalVarFileValue.Close()
formFiles = append(formFiles, formFile{fileBytes: filesLocalVarFileBytes, fileName: filesLocalVarFileName, formFileName: filesLocalVarFormFileName})
}
}
parameterAddToHeaderOrQuery(localVarFormParams, "request", r.request, "", "")
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
File diff suppressed because it is too large Load Diff
-850
View File
@@ -1,850 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
"strings"
"reflect"
)
// MentalModelsAPIService MentalModelsAPI service
type MentalModelsAPIService service
type ApiCreateMentalModelRequest struct {
ctx context.Context
ApiService *MentalModelsAPIService
bankId string
createMentalModelRequest *CreateMentalModelRequest
authorization *string
}
func (r ApiCreateMentalModelRequest) CreateMentalModelRequest(createMentalModelRequest CreateMentalModelRequest) ApiCreateMentalModelRequest {
r.createMentalModelRequest = &createMentalModelRequest
return r
}
func (r ApiCreateMentalModelRequest) Authorization(authorization string) ApiCreateMentalModelRequest {
r.authorization = &authorization
return r
}
func (r ApiCreateMentalModelRequest) Execute() (*CreateMentalModelResponse, *http.Response, error) {
return r.ApiService.CreateMentalModelExecute(r)
}
/*
CreateMentalModel Create mental model
Create a mental model by running reflect with the source query in the background. Returns an operation ID to track progress. The content is auto-generated by the reflect endpoint. Use the operations endpoint to check completion status.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@return ApiCreateMentalModelRequest
*/
func (a *MentalModelsAPIService) CreateMentalModel(ctx context.Context, bankId string) ApiCreateMentalModelRequest {
return ApiCreateMentalModelRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
}
}
// Execute executes the request
// @return CreateMentalModelResponse
func (a *MentalModelsAPIService) CreateMentalModelExecute(r ApiCreateMentalModelRequest) (*CreateMentalModelResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPost
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *CreateMentalModelResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MentalModelsAPIService.CreateMentalModel")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/mental-models"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.createMentalModelRequest == nil {
return localVarReturnValue, nil, reportError("createMentalModelRequest is required and must be specified")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"application/json"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
// body params
localVarPostBody = r.createMentalModelRequest
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiDeleteMentalModelRequest struct {
ctx context.Context
ApiService *MentalModelsAPIService
bankId string
mentalModelId string
authorization *string
}
func (r ApiDeleteMentalModelRequest) Authorization(authorization string) ApiDeleteMentalModelRequest {
r.authorization = &authorization
return r
}
func (r ApiDeleteMentalModelRequest) Execute() (interface{}, *http.Response, error) {
return r.ApiService.DeleteMentalModelExecute(r)
}
/*
DeleteMentalModel Delete mental model
Delete a mental model.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param mentalModelId
@return ApiDeleteMentalModelRequest
*/
func (a *MentalModelsAPIService) DeleteMentalModel(ctx context.Context, bankId string, mentalModelId string) ApiDeleteMentalModelRequest {
return ApiDeleteMentalModelRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
mentalModelId: mentalModelId,
}
}
// Execute executes the request
// @return interface{}
func (a *MentalModelsAPIService) DeleteMentalModelExecute(r ApiDeleteMentalModelRequest) (interface{}, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodDelete
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue interface{}
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MentalModelsAPIService.DeleteMentalModel")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"mental_model_id"+"}", url.PathEscape(parameterValueToString(r.mentalModelId, "mentalModelId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiGetMentalModelRequest struct {
ctx context.Context
ApiService *MentalModelsAPIService
bankId string
mentalModelId string
authorization *string
}
func (r ApiGetMentalModelRequest) Authorization(authorization string) ApiGetMentalModelRequest {
r.authorization = &authorization
return r
}
func (r ApiGetMentalModelRequest) Execute() (*MentalModelResponse, *http.Response, error) {
return r.ApiService.GetMentalModelExecute(r)
}
/*
GetMentalModel Get mental model
Get a specific mental model by ID.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param mentalModelId
@return ApiGetMentalModelRequest
*/
func (a *MentalModelsAPIService) GetMentalModel(ctx context.Context, bankId string, mentalModelId string) ApiGetMentalModelRequest {
return ApiGetMentalModelRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
mentalModelId: mentalModelId,
}
}
// Execute executes the request
// @return MentalModelResponse
func (a *MentalModelsAPIService) GetMentalModelExecute(r ApiGetMentalModelRequest) (*MentalModelResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *MentalModelResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MentalModelsAPIService.GetMentalModel")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"mental_model_id"+"}", url.PathEscape(parameterValueToString(r.mentalModelId, "mentalModelId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiListMentalModelsRequest struct {
ctx context.Context
ApiService *MentalModelsAPIService
bankId string
tags *[]string
tagsMatch *string
limit *int32
offset *int32
authorization *string
}
// Filter by tags
func (r ApiListMentalModelsRequest) Tags(tags []string) ApiListMentalModelsRequest {
r.tags = &tags
return r
}
// How to match tags
func (r ApiListMentalModelsRequest) TagsMatch(tagsMatch string) ApiListMentalModelsRequest {
r.tagsMatch = &tagsMatch
return r
}
func (r ApiListMentalModelsRequest) Limit(limit int32) ApiListMentalModelsRequest {
r.limit = &limit
return r
}
func (r ApiListMentalModelsRequest) Offset(offset int32) ApiListMentalModelsRequest {
r.offset = &offset
return r
}
func (r ApiListMentalModelsRequest) Authorization(authorization string) ApiListMentalModelsRequest {
r.authorization = &authorization
return r
}
func (r ApiListMentalModelsRequest) Execute() (*MentalModelListResponse, *http.Response, error) {
return r.ApiService.ListMentalModelsExecute(r)
}
/*
ListMentalModels List mental models
List user-curated living documents that stay current.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@return ApiListMentalModelsRequest
*/
func (a *MentalModelsAPIService) ListMentalModels(ctx context.Context, bankId string) ApiListMentalModelsRequest {
return ApiListMentalModelsRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
}
}
// Execute executes the request
// @return MentalModelListResponse
func (a *MentalModelsAPIService) ListMentalModelsExecute(r ApiListMentalModelsRequest) (*MentalModelListResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *MentalModelListResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MentalModelsAPIService.ListMentalModels")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/mental-models"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.tags != nil {
t := *r.tags
if reflect.TypeOf(t).Kind() == reflect.Slice {
s := reflect.ValueOf(t)
for i := 0; i < s.Len(); i++ {
parameterAddToHeaderOrQuery(localVarQueryParams, "tags", s.Index(i).Interface(), "form", "multi")
}
} else {
parameterAddToHeaderOrQuery(localVarQueryParams, "tags", t, "form", "multi")
}
}
if r.tagsMatch != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "tags_match", r.tagsMatch, "form", "")
} else {
var defaultValue string = "any"
r.tagsMatch = &defaultValue
}
if r.limit != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "form", "")
} else {
var defaultValue int32 = 100
r.limit = &defaultValue
}
if r.offset != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "form", "")
} else {
var defaultValue int32 = 0
r.offset = &defaultValue
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiRefreshMentalModelRequest struct {
ctx context.Context
ApiService *MentalModelsAPIService
bankId string
mentalModelId string
authorization *string
}
func (r ApiRefreshMentalModelRequest) Authorization(authorization string) ApiRefreshMentalModelRequest {
r.authorization = &authorization
return r
}
func (r ApiRefreshMentalModelRequest) Execute() (*AsyncOperationSubmitResponse, *http.Response, error) {
return r.ApiService.RefreshMentalModelExecute(r)
}
/*
RefreshMentalModel Refresh mental model
Submit an async task to re-run the source query through reflect and update the content.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param mentalModelId
@return ApiRefreshMentalModelRequest
*/
func (a *MentalModelsAPIService) RefreshMentalModel(ctx context.Context, bankId string, mentalModelId string) ApiRefreshMentalModelRequest {
return ApiRefreshMentalModelRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
mentalModelId: mentalModelId,
}
}
// Execute executes the request
// @return AsyncOperationSubmitResponse
func (a *MentalModelsAPIService) RefreshMentalModelExecute(r ApiRefreshMentalModelRequest) (*AsyncOperationSubmitResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPost
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *AsyncOperationSubmitResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MentalModelsAPIService.RefreshMentalModel")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}/refresh"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"mental_model_id"+"}", url.PathEscape(parameterValueToString(r.mentalModelId, "mentalModelId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiUpdateMentalModelRequest struct {
ctx context.Context
ApiService *MentalModelsAPIService
bankId string
mentalModelId string
updateMentalModelRequest *UpdateMentalModelRequest
authorization *string
}
func (r ApiUpdateMentalModelRequest) UpdateMentalModelRequest(updateMentalModelRequest UpdateMentalModelRequest) ApiUpdateMentalModelRequest {
r.updateMentalModelRequest = &updateMentalModelRequest
return r
}
func (r ApiUpdateMentalModelRequest) Authorization(authorization string) ApiUpdateMentalModelRequest {
r.authorization = &authorization
return r
}
func (r ApiUpdateMentalModelRequest) Execute() (*MentalModelResponse, *http.Response, error) {
return r.ApiService.UpdateMentalModelExecute(r)
}
/*
UpdateMentalModel Update mental model
Update a mental model's name and/or source query.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param mentalModelId
@return ApiUpdateMentalModelRequest
*/
func (a *MentalModelsAPIService) UpdateMentalModel(ctx context.Context, bankId string, mentalModelId string) ApiUpdateMentalModelRequest {
return ApiUpdateMentalModelRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
mentalModelId: mentalModelId,
}
}
// Execute executes the request
// @return MentalModelResponse
func (a *MentalModelsAPIService) UpdateMentalModelExecute(r ApiUpdateMentalModelRequest) (*MentalModelResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPatch
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *MentalModelResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MentalModelsAPIService.UpdateMentalModel")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"mental_model_id"+"}", url.PathEscape(parameterValueToString(r.mentalModelId, "mentalModelId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.updateMentalModelRequest == nil {
return localVarReturnValue, nil, reportError("updateMentalModelRequest is required and must be specified")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"application/json"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
// body params
localVarPostBody = r.updateMentalModelRequest
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
-320
View File
@@ -1,320 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
)
// MonitoringAPIService MonitoringAPI service
type MonitoringAPIService service
type ApiGetVersionRequest struct {
ctx context.Context
ApiService *MonitoringAPIService
}
func (r ApiGetVersionRequest) Execute() (*VersionResponse, *http.Response, error) {
return r.ApiService.GetVersionExecute(r)
}
/*
GetVersion Get API version and feature flags
Returns API version information and enabled feature flags. Use this to check which capabilities are available in this deployment.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiGetVersionRequest
*/
func (a *MonitoringAPIService) GetVersion(ctx context.Context) ApiGetVersionRequest {
return ApiGetVersionRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
// @return VersionResponse
func (a *MonitoringAPIService) GetVersionExecute(r ApiGetVersionRequest) (*VersionResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *VersionResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MonitoringAPIService.GetVersion")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/version"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiHealthEndpointHealthGetRequest struct {
ctx context.Context
ApiService *MonitoringAPIService
}
func (r ApiHealthEndpointHealthGetRequest) Execute() (interface{}, *http.Response, error) {
return r.ApiService.HealthEndpointHealthGetExecute(r)
}
/*
HealthEndpointHealthGet Health check endpoint
Checks the health of the API and database connection
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiHealthEndpointHealthGetRequest
*/
func (a *MonitoringAPIService) HealthEndpointHealthGet(ctx context.Context) ApiHealthEndpointHealthGetRequest {
return ApiHealthEndpointHealthGetRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
// @return interface{}
func (a *MonitoringAPIService) HealthEndpointHealthGetExecute(r ApiHealthEndpointHealthGetRequest) (interface{}, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue interface{}
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MonitoringAPIService.HealthEndpointHealthGet")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/health"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiMetricsEndpointMetricsGetRequest struct {
ctx context.Context
ApiService *MonitoringAPIService
}
func (r ApiMetricsEndpointMetricsGetRequest) Execute() (interface{}, *http.Response, error) {
return r.ApiService.MetricsEndpointMetricsGetExecute(r)
}
/*
MetricsEndpointMetricsGet Prometheus metrics endpoint
Exports metrics in Prometheus format for scraping
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiMetricsEndpointMetricsGetRequest
*/
func (a *MonitoringAPIService) MetricsEndpointMetricsGet(ctx context.Context) ApiMetricsEndpointMetricsGetRequest {
return ApiMetricsEndpointMetricsGetRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
// @return interface{}
func (a *MonitoringAPIService) MetricsEndpointMetricsGetExecute(r ApiMetricsEndpointMetricsGetRequest) (interface{}, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue interface{}
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MonitoringAPIService.MetricsEndpointMetricsGet")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/metrics"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
-434
View File
@@ -1,434 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
"strings"
)
// OperationsAPIService OperationsAPI service
type OperationsAPIService service
type ApiCancelOperationRequest struct {
ctx context.Context
ApiService *OperationsAPIService
bankId string
operationId string
authorization *string
}
func (r ApiCancelOperationRequest) Authorization(authorization string) ApiCancelOperationRequest {
r.authorization = &authorization
return r
}
func (r ApiCancelOperationRequest) Execute() (*CancelOperationResponse, *http.Response, error) {
return r.ApiService.CancelOperationExecute(r)
}
/*
CancelOperation Cancel a pending async operation
Cancel a pending async operation by removing it from the queue
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param operationId
@return ApiCancelOperationRequest
*/
func (a *OperationsAPIService) CancelOperation(ctx context.Context, bankId string, operationId string) ApiCancelOperationRequest {
return ApiCancelOperationRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
operationId: operationId,
}
}
// Execute executes the request
// @return CancelOperationResponse
func (a *OperationsAPIService) CancelOperationExecute(r ApiCancelOperationRequest) (*CancelOperationResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodDelete
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *CancelOperationResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OperationsAPIService.CancelOperation")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/operations/{operation_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"operation_id"+"}", url.PathEscape(parameterValueToString(r.operationId, "operationId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiGetOperationStatusRequest struct {
ctx context.Context
ApiService *OperationsAPIService
bankId string
operationId string
authorization *string
}
func (r ApiGetOperationStatusRequest) Authorization(authorization string) ApiGetOperationStatusRequest {
r.authorization = &authorization
return r
}
func (r ApiGetOperationStatusRequest) Execute() (*OperationStatusResponse, *http.Response, error) {
return r.ApiService.GetOperationStatusExecute(r)
}
/*
GetOperationStatus Get operation status
Get the status of a specific async operation. Returns 'pending', 'completed', or 'failed'. Completed operations are removed from storage, so 'completed' means the operation finished successfully.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@param operationId
@return ApiGetOperationStatusRequest
*/
func (a *OperationsAPIService) GetOperationStatus(ctx context.Context, bankId string, operationId string) ApiGetOperationStatusRequest {
return ApiGetOperationStatusRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
operationId: operationId,
}
}
// Execute executes the request
// @return OperationStatusResponse
func (a *OperationsAPIService) GetOperationStatusExecute(r ApiGetOperationStatusRequest) (*OperationStatusResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *OperationStatusResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OperationsAPIService.GetOperationStatus")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/operations/{operation_id}"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarPath = strings.Replace(localVarPath, "{"+"operation_id"+"}", url.PathEscape(parameterValueToString(r.operationId, "operationId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiListOperationsRequest struct {
ctx context.Context
ApiService *OperationsAPIService
bankId string
status *string
limit *int32
offset *int32
authorization *string
}
// Filter by status: pending, completed, or failed
func (r ApiListOperationsRequest) Status(status string) ApiListOperationsRequest {
r.status = &status
return r
}
// Maximum number of operations to return
func (r ApiListOperationsRequest) Limit(limit int32) ApiListOperationsRequest {
r.limit = &limit
return r
}
// Number of operations to skip
func (r ApiListOperationsRequest) Offset(offset int32) ApiListOperationsRequest {
r.offset = &offset
return r
}
func (r ApiListOperationsRequest) Authorization(authorization string) ApiListOperationsRequest {
r.authorization = &authorization
return r
}
func (r ApiListOperationsRequest) Execute() (*OperationsListResponse, *http.Response, error) {
return r.ApiService.ListOperationsExecute(r)
}
/*
ListOperations List async operations
Get a list of async operations for a specific agent, with optional filtering by status. Results are sorted by most recent first.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param bankId
@return ApiListOperationsRequest
*/
func (a *OperationsAPIService) ListOperations(ctx context.Context, bankId string) ApiListOperationsRequest {
return ApiListOperationsRequest{
ApiService: a,
ctx: ctx,
bankId: bankId,
}
}
// Execute executes the request
// @return OperationsListResponse
func (a *OperationsAPIService) ListOperationsExecute(r ApiListOperationsRequest) (*OperationsListResponse, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *OperationsListResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OperationsAPIService.ListOperations")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/default/banks/{bank_id}/operations"
localVarPath = strings.Replace(localVarPath, "{"+"bank_id"+"}", url.PathEscape(parameterValueToString(r.bankId, "bankId")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.status != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "status", r.status, "form", "")
}
if r.limit != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "limit", r.limit, "form", "")
} else {
var defaultValue int32 = 20
r.limit = &defaultValue
}
if r.offset != nil {
parameterAddToHeaderOrQuery(localVarQueryParams, "offset", r.offset, "form", "")
} else {
var defaultValue int32 = 0
r.offset = &defaultValue
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.authorization != nil {
parameterAddToHeaderOrQuery(localVarHeaderParams, "authorization", r.authorization, "simple", "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 422 {
var v HTTPValidationError
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
-676
View File
@@ -1,676 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"bytes"
"context"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"net/http/httputil"
"net/url"
"os"
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
"time"
"unicode/utf8"
)
var (
JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`)
XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`)
queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`)
queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" )
)
// APIClient manages communication with the Hindsight HTTP API API v0.4.11
// In most cases there should be only one, shared, APIClient.
type APIClient struct {
cfg *Configuration
common service // Reuse a single struct instead of allocating one for each service on the heap.
// API Services
BanksAPI *BanksAPIService
DirectivesAPI *DirectivesAPIService
DocumentsAPI *DocumentsAPIService
EntitiesAPI *EntitiesAPIService
FilesAPI *FilesAPIService
MemoryAPI *MemoryAPIService
MentalModelsAPI *MentalModelsAPIService
MonitoringAPI *MonitoringAPIService
OperationsAPI *OperationsAPIService
}
type service struct {
client *APIClient
}
// NewAPIClient creates a new API client. Requires a userAgent string describing your application.
// optionally a custom http.Client to allow for advanced features such as caching.
func NewAPIClient(cfg *Configuration) *APIClient {
if cfg.HTTPClient == nil {
cfg.HTTPClient = http.DefaultClient
}
c := &APIClient{}
c.cfg = cfg
c.common.client = c
// API Services
c.BanksAPI = (*BanksAPIService)(&c.common)
c.DirectivesAPI = (*DirectivesAPIService)(&c.common)
c.DocumentsAPI = (*DocumentsAPIService)(&c.common)
c.EntitiesAPI = (*EntitiesAPIService)(&c.common)
c.FilesAPI = (*FilesAPIService)(&c.common)
c.MemoryAPI = (*MemoryAPIService)(&c.common)
c.MentalModelsAPI = (*MentalModelsAPIService)(&c.common)
c.MonitoringAPI = (*MonitoringAPIService)(&c.common)
c.OperationsAPI = (*OperationsAPIService)(&c.common)
return c
}
func atoi(in string) (int, error) {
return strconv.Atoi(in)
}
// selectHeaderContentType select a content type from the available list.
func selectHeaderContentType(contentTypes []string) string {
if len(contentTypes) == 0 {
return ""
}
if contains(contentTypes, "application/json") {
return "application/json"
}
return contentTypes[0] // use the first content type specified in 'consumes'
}
// selectHeaderAccept join all accept types and return
func selectHeaderAccept(accepts []string) string {
if len(accepts) == 0 {
return ""
}
if contains(accepts, "application/json") {
return "application/json"
}
return strings.Join(accepts, ",")
}
// contains is a case insensitive match, finding needle in a haystack
func contains(haystack []string, needle string) bool {
for _, a := range haystack {
if strings.EqualFold(a, needle) {
return true
}
}
return false
}
// Verify optional parameters are of the correct type.
func typeCheckParameter(obj interface{}, expected string, name string) error {
// Make sure there is an object.
if obj == nil {
return nil
}
// Check the type is as expected.
if reflect.TypeOf(obj).String() != expected {
return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String())
}
return nil
}
func parameterValueToString( obj interface{}, key string ) string {
if reflect.TypeOf(obj).Kind() != reflect.Ptr {
return fmt.Sprintf("%v", obj)
}
var param,ok = obj.(MappedNullable)
if !ok {
return ""
}
dataMap,err := param.ToMap()
if err != nil {
return ""
}
return fmt.Sprintf("%v", dataMap[key])
}
// parameterAddToHeaderOrQuery adds the provided object to the request header or url query
// supporting deep object syntax
func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, style string, collectionType string) {
var v = reflect.ValueOf(obj)
var value = ""
if v == reflect.ValueOf(nil) {
value = "null"
} else {
switch v.Kind() {
case reflect.Invalid:
value = "invalid"
case reflect.Struct:
if t,ok := obj.(MappedNullable); ok {
dataMap,err := t.ToMap()
if err != nil {
return
}
parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, style, collectionType)
return
}
if t, ok := obj.(time.Time); ok {
parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339Nano), style, collectionType)
return
}
value = v.Type().String() + " value"
case reflect.Slice:
var indValue = reflect.ValueOf(obj)
if indValue == reflect.ValueOf(nil) {
return
}
var lenIndValue = indValue.Len()
for i:=0;i<lenIndValue;i++ {
var arrayValue = indValue.Index(i)
var keyPrefixForCollectionType = keyPrefix
if style == "deepObject" {
keyPrefixForCollectionType = keyPrefix + "[" + strconv.Itoa(i) + "]"
}
parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefixForCollectionType, arrayValue.Interface(), style, collectionType)
}
return
case reflect.Map:
var indValue = reflect.ValueOf(obj)
if indValue == reflect.ValueOf(nil) {
return
}
iter := indValue.MapRange()
for iter.Next() {
k,v := iter.Key(), iter.Value()
parameterAddToHeaderOrQuery(headerOrQueryParams, fmt.Sprintf("%s[%s]", keyPrefix, k.String()), v.Interface(), style, collectionType)
}
return
case reflect.Interface:
fallthrough
case reflect.Ptr:
parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, v.Elem().Interface(), style, collectionType)
return
case reflect.Int, reflect.Int8, reflect.Int16,
reflect.Int32, reflect.Int64:
value = strconv.FormatInt(v.Int(), 10)
case reflect.Uint, reflect.Uint8, reflect.Uint16,
reflect.Uint32, reflect.Uint64, reflect.Uintptr:
value = strconv.FormatUint(v.Uint(), 10)
case reflect.Float32, reflect.Float64:
value = strconv.FormatFloat(v.Float(), 'g', -1, 32)
case reflect.Bool:
value = strconv.FormatBool(v.Bool())
case reflect.String:
value = v.String()
default:
value = v.Type().String() + " value"
}
}
switch valuesMap := headerOrQueryParams.(type) {
case url.Values:
if collectionType == "csv" && valuesMap.Get(keyPrefix) != "" {
valuesMap.Set(keyPrefix, valuesMap.Get(keyPrefix) + "," + value)
} else {
valuesMap.Add(keyPrefix, value)
}
break
case map[string]string:
valuesMap[keyPrefix] = value
break
}
}
// helper for converting interface{} parameters to json strings
func parameterToJson(obj interface{}) (string, error) {
jsonBuf, err := json.Marshal(obj)
if err != nil {
return "", err
}
return string(jsonBuf), err
}
// callAPI do the request.
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
if c.cfg.Debug {
dump, err := httputil.DumpRequestOut(request, true)
if err != nil {
return nil, err
}
log.Printf("\n%s\n", string(dump))
}
resp, err := c.cfg.HTTPClient.Do(request)
if err != nil {
return resp, err
}
if c.cfg.Debug {
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
return resp, err
}
log.Printf("\n%s\n", string(dump))
}
return resp, err
}
// Allow modification of underlying config for alternate implementations and testing
// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior
func (c *APIClient) GetConfig() *Configuration {
return c.cfg
}
type formFile struct {
fileBytes []byte
fileName string
formFileName string
}
// prepareRequest build the request
func (c *APIClient) prepareRequest(
ctx context.Context,
path string, method string,
postBody interface{},
headerParams map[string]string,
queryParams url.Values,
formParams url.Values,
formFiles []formFile) (localVarRequest *http.Request, err error) {
var body *bytes.Buffer
// Detect postBody type and post.
if postBody != nil {
contentType := headerParams["Content-Type"]
if contentType == "" {
contentType = detectContentType(postBody)
headerParams["Content-Type"] = contentType
}
body, err = setBody(postBody, contentType)
if err != nil {
return nil, err
}
}
// add form parameters and file if available.
if strings.HasPrefix(headerParams["Content-Type"], "multipart/form-data") && len(formParams) > 0 || (len(formFiles) > 0) {
if body != nil {
return nil, errors.New("Cannot specify postBody and multipart form at the same time.")
}
body = &bytes.Buffer{}
w := multipart.NewWriter(body)
for k, v := range formParams {
for _, iv := range v {
if strings.HasPrefix(k, "@") { // file
err = addFile(w, k[1:], iv)
if err != nil {
return nil, err
}
} else { // form value
w.WriteField(k, iv)
}
}
}
for _, formFile := range formFiles {
if len(formFile.fileBytes) > 0 && formFile.fileName != "" {
w.Boundary()
part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName))
if err != nil {
return nil, err
}
_, err = part.Write(formFile.fileBytes)
if err != nil {
return nil, err
}
}
}
// Set the Boundary in the Content-Type
headerParams["Content-Type"] = w.FormDataContentType()
// Set Content-Length
headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len())
w.Close()
}
if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 {
if body != nil {
return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.")
}
body = &bytes.Buffer{}
body.WriteString(formParams.Encode())
// Set Content-Length
headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len())
}
// Setup path and query parameters
url, err := url.Parse(path)
if err != nil {
return nil, err
}
// Override request host, if applicable
if c.cfg.Host != "" {
url.Host = c.cfg.Host
}
// Override request scheme, if applicable
if c.cfg.Scheme != "" {
url.Scheme = c.cfg.Scheme
}
// Adding Query Param
query := url.Query()
for k, v := range queryParams {
for _, iv := range v {
query.Add(k, iv)
}
}
// Encode the parameters.
url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string {
pieces := strings.Split(s, "=")
pieces[0] = queryDescape.Replace(pieces[0])
return strings.Join(pieces, "=")
})
// Generate a new request
if body != nil {
localVarRequest, err = http.NewRequest(method, url.String(), body)
} else {
localVarRequest, err = http.NewRequest(method, url.String(), nil)
}
if err != nil {
return nil, err
}
// add header parameters, if any
if len(headerParams) > 0 {
headers := http.Header{}
for h, v := range headerParams {
headers[h] = []string{v}
}
localVarRequest.Header = headers
}
// Add the user agent to the request.
localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent)
if ctx != nil {
// add context to the request
localVarRequest = localVarRequest.WithContext(ctx)
// Walk through any authentication.
}
for header, value := range c.cfg.DefaultHeader {
localVarRequest.Header.Add(header, value)
}
return localVarRequest, nil
}
func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
if len(b) == 0 {
return nil
}
if s, ok := v.(*string); ok {
*s = string(b)
return nil
}
if f, ok := v.(*os.File); ok {
f, err = os.CreateTemp("", "HttpClientFile")
if err != nil {
return
}
_, err = f.Write(b)
if err != nil {
return
}
_, err = f.Seek(0, io.SeekStart)
return
}
if f, ok := v.(**os.File); ok {
*f, err = os.CreateTemp("", "HttpClientFile")
if err != nil {
return
}
_, err = (*f).Write(b)
if err != nil {
return
}
_, err = (*f).Seek(0, io.SeekStart)
return
}
if XmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil {
return err
}
return nil
}
if JsonCheck.MatchString(contentType) {
if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas
if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined
if err = unmarshalObj.UnmarshalJSON(b); err != nil {
return err
}
} else {
return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined")
}
} else if err = json.Unmarshal(b, v); err != nil { // simple model
return err
}
return nil
}
return errors.New("undefined response type")
}
// Add a file to the multipart request
func addFile(w *multipart.Writer, fieldName, path string) error {
file, err := os.Open(filepath.Clean(path))
if err != nil {
return err
}
err = file.Close()
if err != nil {
return err
}
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
if err != nil {
return err
}
_, err = io.Copy(part, file)
return err
}
// Set request body from an interface{}
func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) {
if bodyBuf == nil {
bodyBuf = &bytes.Buffer{}
}
if reader, ok := body.(io.Reader); ok {
_, err = bodyBuf.ReadFrom(reader)
} else if fp, ok := body.(*os.File); ok {
_, err = bodyBuf.ReadFrom(fp)
} else if b, ok := body.([]byte); ok {
_, err = bodyBuf.Write(b)
} else if s, ok := body.(string); ok {
_, err = bodyBuf.WriteString(s)
} else if s, ok := body.(*string); ok {
_, err = bodyBuf.WriteString(*s)
} else if JsonCheck.MatchString(contentType) {
err = json.NewEncoder(bodyBuf).Encode(body)
} else if XmlCheck.MatchString(contentType) {
var bs []byte
bs, err = xml.Marshal(body)
if err == nil {
bodyBuf.Write(bs)
}
}
if err != nil {
return nil, err
}
if bodyBuf.Len() == 0 {
err = fmt.Errorf("invalid body type %s\n", contentType)
return nil, err
}
return bodyBuf, nil
}
// detectContentType method is used to figure out `Request.Body` content type for request header
func detectContentType(body interface{}) string {
contentType := "text/plain; charset=utf-8"
kind := reflect.TypeOf(body).Kind()
switch kind {
case reflect.Struct, reflect.Map, reflect.Ptr:
contentType = "application/json; charset=utf-8"
case reflect.String:
contentType = "text/plain; charset=utf-8"
default:
if b, ok := body.([]byte); ok {
contentType = http.DetectContentType(b)
} else if kind == reflect.Slice {
contentType = "application/json; charset=utf-8"
}
}
return contentType
}
// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go
type cacheControl map[string]string
func parseCacheControl(headers http.Header) cacheControl {
cc := cacheControl{}
ccHeader := headers.Get("Cache-Control")
for _, part := range strings.Split(ccHeader, ",") {
part = strings.Trim(part, " ")
if part == "" {
continue
}
if strings.ContainsRune(part, '=') {
keyval := strings.Split(part, "=")
cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",")
} else {
cc[part] = ""
}
}
return cc
}
// CacheExpires helper function to determine remaining time before repeating a request.
func CacheExpires(r *http.Response) time.Time {
// Figure out when the cache expires.
var expires time.Time
now, err := time.Parse(time.RFC1123, r.Header.Get("date"))
if err != nil {
return time.Now()
}
respCacheControl := parseCacheControl(r.Header)
if maxAge, ok := respCacheControl["max-age"]; ok {
lifetime, err := time.ParseDuration(maxAge + "s")
if err != nil {
expires = now
} else {
expires = now.Add(lifetime)
}
} else {
expiresHeader := r.Header.Get("Expires")
if expiresHeader != "" {
expires, err = time.Parse(time.RFC1123, expiresHeader)
if err != nil {
expires = now
}
}
}
return expires
}
func strlen(s string) int {
return utf8.RuneCountInString(s)
}
// GenericOpenAPIError Provides access to the body, error and model on returned errors.
type GenericOpenAPIError struct {
body []byte
error string
model interface{}
}
// Error returns non-empty string if there was an error.
func (e GenericOpenAPIError) Error() string {
return e.error
}
// Body returns the raw bytes of the response
func (e GenericOpenAPIError) Body() []byte {
return e.body
}
// Model returns the unpacked model of the error
func (e GenericOpenAPIError) Model() interface{} {
return e.model
}
// format error message using title and detail when model implements rfc7807
func formatErrorMessage(status string, v interface{}) string {
str := ""
metaValue := reflect.ValueOf(v).Elem()
if metaValue.Kind() == reflect.Struct {
field := metaValue.FieldByName("Title")
if field != (reflect.Value{}) {
str = fmt.Sprintf("%s", field.Interface())
}
field = metaValue.FieldByName("Detail")
if field != (reflect.Value{}) {
str = fmt.Sprintf("%s (%s)", str, field.Interface())
}
}
return strings.TrimSpace(fmt.Sprintf("%s %s", status, str))
}
-215
View File
@@ -1,215 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"context"
"fmt"
"net/http"
"strings"
)
// contextKeys are used to identify the type of value in the context.
// Since these are string, it is possible to get a short description of the
// context key for logging and debugging using key.String().
type contextKey string
func (c contextKey) String() string {
return "auth " + string(c)
}
var (
// ContextServerIndex uses a server configuration from the index.
ContextServerIndex = contextKey("serverIndex")
// ContextOperationServerIndices uses a server configuration from the index mapping.
ContextOperationServerIndices = contextKey("serverOperationIndices")
// ContextServerVariables overrides a server configuration variables.
ContextServerVariables = contextKey("serverVariables")
// ContextOperationServerVariables overrides a server configuration variables using operation specific values.
ContextOperationServerVariables = contextKey("serverOperationVariables")
)
// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth
type BasicAuth struct {
UserName string `json:"userName,omitempty"`
Password string `json:"password,omitempty"`
}
// APIKey provides API key based authentication to a request passed via context using ContextAPIKey
type APIKey struct {
Key string
Prefix string
}
// ServerVariable stores the information about a server variable
type ServerVariable struct {
Description string
DefaultValue string
EnumValues []string
}
// ServerConfiguration stores the information about a server
type ServerConfiguration struct {
URL string
Description string
Variables map[string]ServerVariable
}
// ServerConfigurations stores multiple ServerConfiguration items
type ServerConfigurations []ServerConfiguration
// Configuration stores the configuration of the API client
type Configuration struct {
Host string `json:"host,omitempty"`
Scheme string `json:"scheme,omitempty"`
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
Debug bool `json:"debug,omitempty"`
Servers ServerConfigurations
OperationServers map[string]ServerConfigurations
HTTPClient *http.Client
}
// NewConfiguration returns a new Configuration object
func NewConfiguration() *Configuration {
cfg := &Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Servers: ServerConfigurations{
{
URL: "",
Description: "No description provided",
},
},
OperationServers: map[string]ServerConfigurations{
},
}
return cfg
}
// AddDefaultHeader adds a new HTTP header to the default header in the request
func (c *Configuration) AddDefaultHeader(key string, value string) {
c.DefaultHeader[key] = value
}
// URL formats template on a index using given variables
func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) {
if index < 0 || len(sc) <= index {
return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1)
}
server := sc[index]
url := server.URL
// go through variables and replace placeholders
for name, variable := range server.Variables {
if value, ok := variables[name]; ok {
found := bool(len(variable.EnumValues) == 0)
for _, enumValue := range variable.EnumValues {
if value == enumValue {
found = true
}
}
if !found {
return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues)
}
url = strings.Replace(url, "{"+name+"}", value, -1)
} else {
url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1)
}
}
return url, nil
}
// ServerURL returns URL based on server settings
func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) {
return c.Servers.URL(index, variables)
}
func getServerIndex(ctx context.Context) (int, error) {
si := ctx.Value(ContextServerIndex)
if si != nil {
if index, ok := si.(int); ok {
return index, nil
}
return 0, reportError("Invalid type %T should be int", si)
}
return 0, nil
}
func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) {
osi := ctx.Value(ContextOperationServerIndices)
if osi != nil {
if operationIndices, ok := osi.(map[string]int); !ok {
return 0, reportError("Invalid type %T should be map[string]int", osi)
} else {
index, ok := operationIndices[endpoint]
if ok {
return index, nil
}
}
}
return getServerIndex(ctx)
}
func getServerVariables(ctx context.Context) (map[string]string, error) {
sv := ctx.Value(ContextServerVariables)
if sv != nil {
if variables, ok := sv.(map[string]string); ok {
return variables, nil
}
return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv)
}
return nil, nil
}
func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) {
osv := ctx.Value(ContextOperationServerVariables)
if osv != nil {
if operationVariables, ok := osv.(map[string]map[string]string); !ok {
return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv)
} else {
variables, ok := operationVariables[endpoint]
if ok {
return variables, nil
}
}
}
return getServerVariables(ctx)
}
// ServerURLWithContext returns a new server URL given an endpoint
func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) {
sc, ok := c.OperationServers[endpoint]
if !ok {
sc = c.Servers
}
if ctx == nil {
return sc.URL(0, nil)
}
index, err := getServerOperationIndex(ctx, endpoint)
if err != nil {
return "", err
}
variables, err := getServerOperationVariables(ctx, endpoint)
if err != nil {
return "", err
}
return sc.URL(index, variables)
}
-11
View File
@@ -1,11 +0,0 @@
module github.com/vectorize-io/hindsight/hindsight-clients/go
go 1.18
require github.com/stretchr/testify v1.11.1
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-10
View File
@@ -1,10 +0,0 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-17
View File
@@ -1,17 +0,0 @@
package hindsight
// NewAPIClientWithToken creates a new API client configured with a base URL and API token.
// The token is sent as a Bearer token in the Authorization header for all requests.
//
// Example:
//
// client := hindsight.NewAPIClientWithToken("https://api.example.com", "your-api-token")
// resp, _, err := client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(req).Execute()
func NewAPIClientWithToken(baseURL, token string) *APIClient {
cfg := NewConfiguration()
cfg.Servers = ServerConfigurations{
{URL: baseURL},
}
cfg.AddDefaultHeader("Authorization", "Bearer "+token)
return NewAPIClient(cfg)
}
-479
View File
@@ -1,479 +0,0 @@
//go:build integration
package hindsight
import (
"context"
"fmt"
"os"
"testing"
"time"
)
func apiURL(t *testing.T) string {
t.Helper()
u := os.Getenv("HINDSIGHT_API_URL")
if u == "" {
u = "http://localhost:8888"
}
return u
}
func newClient(t *testing.T) *APIClient {
t.Helper()
cfg := NewConfiguration()
cfg.Servers = ServerConfigurations{
{URL: apiURL(t)},
}
return NewAPIClient(cfg)
}
func uniqueBank(t *testing.T) string {
t.Helper()
return fmt.Sprintf("go_test_%d", time.Now().UnixNano())
}
// --- Retain tests ---
func TestRetainSingle(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
req := RetainRequest{
Items: []MemoryItem{
{Content: "Alice loves artificial intelligence and machine learning"},
},
}
resp, httpResp, err := client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if !resp.GetSuccess() {
t.Error("expected success=true")
}
}
func TestRetainWithContext(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
timestamp := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
req := RetainRequest{
Items: []MemoryItem{
{
Content: "Bob went hiking in the mountains",
Timestamp: *NewNullableTime(PtrTime(timestamp)),
Context: *NewNullableString(PtrString("outdoor activities")),
},
},
}
resp, httpResp, err := client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if !resp.GetSuccess() {
t.Error("expected success=true")
}
}
func TestRetainBatch(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
req := RetainRequest{
Items: []MemoryItem{
{Content: "Charlie enjoys reading science fiction books"},
{Content: "Diana is learning to play the guitar"},
{Content: "Eve completed a marathon last month"},
},
}
resp, httpResp, err := client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if !resp.GetSuccess() {
t.Error("expected success=true")
}
if resp.GetItemsCount() != 3 {
t.Errorf("expected items_count=3, got %d", resp.GetItemsCount())
}
}
func TestRetainWithTags(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
req := RetainRequest{
Items: []MemoryItem{
{
Content: "New feature implementation for project Z",
Tags: []string{"project_z", "features"},
},
},
}
resp, httpResp, err := client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if !resp.GetSuccess() {
t.Error("expected success=true")
}
}
func TestRetainBatchWithDocumentTags(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
req := RetainRequest{
Items: []MemoryItem{
{Content: "Document with tags test 1"},
{Content: "Document with tags test 2"},
},
DocumentTags: []string{"test_doc", "batch"},
}
resp, httpResp, err := client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if !resp.GetSuccess() {
t.Error("expected success=true")
}
}
// --- Recall tests ---
func setupRecallBank(t *testing.T, client *APIClient, bankID string) {
t.Helper()
ctx := context.Background()
req := RetainRequest{
Items: []MemoryItem{
{Content: "Alice enjoys hiking in the mountains"},
{Content: "Bob loves to read science fiction novels"},
{Content: "Charlie is learning to play the piano"},
},
}
_, _, err := client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
// Give the system time to process
time.Sleep(time.Second)
}
func TestRecallBasic(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
setupRecallBank(t, client, bankID)
req := RecallRequest{
Query: "outdoor activities",
}
resp, httpResp, err := client.MemoryAPI.RecallMemories(ctx, bankID).RecallRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if resp.Results == nil {
t.Error("expected results, got nil")
}
}
func TestRecallWithMaxTokens(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
setupRecallBank(t, client, bankID)
req := RecallRequest{
Query: "outdoor activities",
MaxTokens: PtrInt32(1024),
}
resp, httpResp, err := client.MemoryAPI.RecallMemories(ctx, bankID).RecallRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if resp.Results == nil {
t.Error("expected results, got nil")
}
}
func TestRecallFullFeatured(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
setupRecallBank(t, client, bankID)
req := RecallRequest{
Query: "What are people's hobbies?",
Types: []string{"world"},
MaxTokens: PtrInt32(2048),
Trace: PtrBool(true),
}
resp, httpResp, err := client.MemoryAPI.RecallMemories(ctx, bankID).RecallRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if resp.Results == nil {
t.Error("expected results, got nil")
}
// Verify trace data is present
if resp.Trace != nil && len(resp.Trace) > 0 {
t.Logf("✓ Trace data received with %d keys", len(resp.Trace))
}
}
// --- Reflect tests ---
func setupReflectBank(t *testing.T, client *APIClient, bankID string) {
t.Helper()
ctx := context.Background()
// Create bank with mission
createReq := CreateBankRequest{
Mission: *NewNullableString(PtrString("I am a helpful AI assistant interested in technology and science.")),
}
_, _, err := client.BanksAPI.CreateOrUpdateBank(ctx, bankID).CreateBankRequest(createReq).Execute()
if err != nil {
t.Fatal(err)
}
// Add memories
retainReq := RetainRequest{
Items: []MemoryItem{
{Content: "Quantum computing uses quantum bits (qubits) for processing"},
{Content: "Neural networks are inspired by biological neurons"},
},
}
_, _, err = client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(retainReq).Execute()
if err != nil {
t.Fatal(err)
}
time.Sleep(time.Second)
}
func TestReflectBasic(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
setupReflectBank(t, client, bankID)
req := ReflectRequest{
Query: "What do you know about computing?",
}
resp, httpResp, err := client.MemoryAPI.Reflect(ctx, bankID).ReflectRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if resp.GetText() == "" {
t.Error("expected non-empty answer")
}
}
func TestReflectWithMaxTokens(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
setupReflectBank(t, client, bankID)
req := ReflectRequest{
Query: "Tell me about neural networks",
MaxTokens: PtrInt32(500),
}
resp, httpResp, err := client.MemoryAPI.Reflect(ctx, bankID).ReflectRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if resp.GetText() == "" {
t.Error("expected non-empty answer")
}
}
// --- Bank tests ---
func TestCreateBank(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
req := CreateBankRequest{
Mission: *NewNullableString(PtrString("Test mission")),
}
resp, httpResp, err := client.BanksAPI.CreateOrUpdateBank(ctx, bankID).CreateBankRequest(req).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if resp.GetBankId() != bankID {
t.Errorf("expected bank_id=%s, got %s", bankID, resp.GetBankId())
}
}
func TestSetMission(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
// Create bank with initial mission
createReq := CreateBankRequest{
Mission: *NewNullableString(PtrString("Initial mission")),
}
_, _, err := client.BanksAPI.CreateOrUpdateBank(ctx, bankID).CreateBankRequest(createReq).Execute()
if err != nil {
t.Fatal(err)
}
// Update mission by creating/updating bank again
updateReq := CreateBankRequest{
Mission: *NewNullableString(PtrString("Updated mission")),
}
resp, httpResp, err := client.BanksAPI.CreateOrUpdateBank(ctx, bankID).CreateBankRequest(updateReq).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if resp.GetMission() != "Updated mission" {
t.Errorf("expected mission='Updated mission', got %s", resp.GetMission())
}
}
func TestListBanks(t *testing.T) {
client := newClient(t)
ctx := context.Background()
resp, httpResp, err := client.BanksAPI.ListBanks(ctx).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if resp.Banks == nil {
t.Error("expected banks list, got nil")
}
}
func TestDeleteBank(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
// Create bank
createReq := CreateBankRequest{}
_, _, err := client.BanksAPI.CreateOrUpdateBank(ctx, bankID).CreateBankRequest(createReq).Execute()
if err != nil {
t.Fatal(err)
}
// Delete bank
resp, httpResp, err := client.BanksAPI.DeleteBank(ctx, bankID).Execute()
if err != nil {
t.Fatal(err)
}
defer httpResp.Body.Close()
if !resp.GetSuccess() {
t.Error("expected success=true")
}
}
// --- End-to-end workflow test ---
func TestCompleteWorkflow(t *testing.T) {
client := newClient(t)
ctx := context.Background()
bankID := uniqueBank(t)
// 1. Create bank
createReq := CreateBankRequest{
Mission: *NewNullableString(PtrString("I am a helpful assistant")),
}
_, _, err := client.BanksAPI.CreateOrUpdateBank(ctx, bankID).CreateBankRequest(createReq).Execute()
if err != nil {
t.Fatal(err)
}
// 2. Retain memories
retainReq := RetainRequest{
Items: []MemoryItem{
{Content: "Paris is the capital of France"},
{Content: "The Eiffel Tower is in Paris"},
},
}
retainResp, _, err := client.MemoryAPI.RetainMemories(ctx, bankID).RetainRequest(retainReq).Execute()
if err != nil {
t.Fatal(err)
}
if !retainResp.GetSuccess() {
t.Error("retain failed")
}
time.Sleep(time.Second)
// 3. Recall
recallReq := RecallRequest{
Query: "What is in Paris?",
}
recallResp, _, err := client.MemoryAPI.RecallMemories(ctx, bankID).RecallRequest(recallReq).Execute()
if err != nil {
t.Fatal(err)
}
if len(recallResp.Results) == 0 {
t.Error("expected recall results")
}
// 4. Reflect
reflectReq := ReflectRequest{
Query: "Tell me about Paris",
}
reflectResp, _, err := client.MemoryAPI.Reflect(ctx, bankID).ReflectRequest(reflectReq).Execute()
if err != nil {
t.Fatal(err)
}
if reflectResp.GetText() == "" {
t.Error("expected reflect answer")
}
t.Log("✓ Complete workflow passed")
}
@@ -1,200 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the AddBackgroundRequest type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &AddBackgroundRequest{}
// AddBackgroundRequest Request model for adding/merging background information. Deprecated: use SetMissionRequest instead.
type AddBackgroundRequest struct {
// New background information to add or merge
Content string `json:"content"`
// Deprecated - disposition is no longer auto-inferred from mission
UpdateDisposition *bool `json:"update_disposition,omitempty"`
}
type _AddBackgroundRequest AddBackgroundRequest
// NewAddBackgroundRequest instantiates a new AddBackgroundRequest object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewAddBackgroundRequest(content string) *AddBackgroundRequest {
this := AddBackgroundRequest{}
this.Content = content
var updateDisposition bool = true
this.UpdateDisposition = &updateDisposition
return &this
}
// NewAddBackgroundRequestWithDefaults instantiates a new AddBackgroundRequest object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewAddBackgroundRequestWithDefaults() *AddBackgroundRequest {
this := AddBackgroundRequest{}
var updateDisposition bool = true
this.UpdateDisposition = &updateDisposition
return &this
}
// GetContent returns the Content field value
func (o *AddBackgroundRequest) GetContent() string {
if o == nil {
var ret string
return ret
}
return o.Content
}
// GetContentOk returns a tuple with the Content field value
// and a boolean to check if the value has been set.
func (o *AddBackgroundRequest) GetContentOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Content, true
}
// SetContent sets field value
func (o *AddBackgroundRequest) SetContent(v string) {
o.Content = v
}
// GetUpdateDisposition returns the UpdateDisposition field value if set, zero value otherwise.
func (o *AddBackgroundRequest) GetUpdateDisposition() bool {
if o == nil || IsNil(o.UpdateDisposition) {
var ret bool
return ret
}
return *o.UpdateDisposition
}
// GetUpdateDispositionOk returns a tuple with the UpdateDisposition field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AddBackgroundRequest) GetUpdateDispositionOk() (*bool, bool) {
if o == nil || IsNil(o.UpdateDisposition) {
return nil, false
}
return o.UpdateDisposition, true
}
// HasUpdateDisposition returns a boolean if a field has been set.
func (o *AddBackgroundRequest) HasUpdateDisposition() bool {
if o != nil && !IsNil(o.UpdateDisposition) {
return true
}
return false
}
// SetUpdateDisposition gets a reference to the given bool and assigns it to the UpdateDisposition field.
func (o *AddBackgroundRequest) SetUpdateDisposition(v bool) {
o.UpdateDisposition = &v
}
func (o AddBackgroundRequest) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o AddBackgroundRequest) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["content"] = o.Content
if !IsNil(o.UpdateDisposition) {
toSerialize["update_disposition"] = o.UpdateDisposition
}
return toSerialize, nil
}
func (o *AddBackgroundRequest) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"content",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varAddBackgroundRequest := _AddBackgroundRequest{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varAddBackgroundRequest)
if err != nil {
return err
}
*o = AddBackgroundRequest(varAddBackgroundRequest)
return err
}
type NullableAddBackgroundRequest struct {
value *AddBackgroundRequest
isSet bool
}
func (v NullableAddBackgroundRequest) Get() *AddBackgroundRequest {
return v.value
}
func (v *NullableAddBackgroundRequest) Set(val *AddBackgroundRequest) {
v.value = val
v.isSet = true
}
func (v NullableAddBackgroundRequest) IsSet() bool {
return v.isSet
}
func (v *NullableAddBackgroundRequest) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableAddBackgroundRequest(val *AddBackgroundRequest) *NullableAddBackgroundRequest {
return &NullableAddBackgroundRequest{value: val, isSet: true}
}
func (v NullableAddBackgroundRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableAddBackgroundRequest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,186 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the AsyncOperationSubmitResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &AsyncOperationSubmitResponse{}
// AsyncOperationSubmitResponse Response model for submitting an async operation.
type AsyncOperationSubmitResponse struct {
OperationId string `json:"operation_id"`
Status string `json:"status"`
}
type _AsyncOperationSubmitResponse AsyncOperationSubmitResponse
// NewAsyncOperationSubmitResponse instantiates a new AsyncOperationSubmitResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewAsyncOperationSubmitResponse(operationId string, status string) *AsyncOperationSubmitResponse {
this := AsyncOperationSubmitResponse{}
this.OperationId = operationId
this.Status = status
return &this
}
// NewAsyncOperationSubmitResponseWithDefaults instantiates a new AsyncOperationSubmitResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewAsyncOperationSubmitResponseWithDefaults() *AsyncOperationSubmitResponse {
this := AsyncOperationSubmitResponse{}
return &this
}
// GetOperationId returns the OperationId field value
func (o *AsyncOperationSubmitResponse) GetOperationId() string {
if o == nil {
var ret string
return ret
}
return o.OperationId
}
// GetOperationIdOk returns a tuple with the OperationId field value
// and a boolean to check if the value has been set.
func (o *AsyncOperationSubmitResponse) GetOperationIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.OperationId, true
}
// SetOperationId sets field value
func (o *AsyncOperationSubmitResponse) SetOperationId(v string) {
o.OperationId = v
}
// GetStatus returns the Status field value
func (o *AsyncOperationSubmitResponse) GetStatus() string {
if o == nil {
var ret string
return ret
}
return o.Status
}
// GetStatusOk returns a tuple with the Status field value
// and a boolean to check if the value has been set.
func (o *AsyncOperationSubmitResponse) GetStatusOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Status, true
}
// SetStatus sets field value
func (o *AsyncOperationSubmitResponse) SetStatus(v string) {
o.Status = v
}
func (o AsyncOperationSubmitResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o AsyncOperationSubmitResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["operation_id"] = o.OperationId
toSerialize["status"] = o.Status
return toSerialize, nil
}
func (o *AsyncOperationSubmitResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"operation_id",
"status",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varAsyncOperationSubmitResponse := _AsyncOperationSubmitResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varAsyncOperationSubmitResponse)
if err != nil {
return err
}
*o = AsyncOperationSubmitResponse(varAsyncOperationSubmitResponse)
return err
}
type NullableAsyncOperationSubmitResponse struct {
value *AsyncOperationSubmitResponse
isSet bool
}
func (v NullableAsyncOperationSubmitResponse) Get() *AsyncOperationSubmitResponse {
return v.value
}
func (v *NullableAsyncOperationSubmitResponse) Set(val *AsyncOperationSubmitResponse) {
v.value = val
v.isSet = true
}
func (v NullableAsyncOperationSubmitResponse) IsSet() bool {
return v.isSet
}
func (v *NullableAsyncOperationSubmitResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableAsyncOperationSubmitResponse(val *AsyncOperationSubmitResponse) *NullableAsyncOperationSubmitResponse {
return &NullableAsyncOperationSubmitResponse{value: val, isSet: true}
}
func (v NullableAsyncOperationSubmitResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableAsyncOperationSubmitResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,250 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the BackgroundResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &BackgroundResponse{}
// BackgroundResponse Response model for background update. Deprecated: use MissionResponse instead.
type BackgroundResponse struct {
Mission string `json:"mission"`
Background NullableString `json:"background,omitempty"`
Disposition NullableDispositionTraits `json:"disposition,omitempty"`
}
type _BackgroundResponse BackgroundResponse
// NewBackgroundResponse instantiates a new BackgroundResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBackgroundResponse(mission string) *BackgroundResponse {
this := BackgroundResponse{}
this.Mission = mission
return &this
}
// NewBackgroundResponseWithDefaults instantiates a new BackgroundResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBackgroundResponseWithDefaults() *BackgroundResponse {
this := BackgroundResponse{}
return &this
}
// GetMission returns the Mission field value
func (o *BackgroundResponse) GetMission() string {
if o == nil {
var ret string
return ret
}
return o.Mission
}
// GetMissionOk returns a tuple with the Mission field value
// and a boolean to check if the value has been set.
func (o *BackgroundResponse) GetMissionOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Mission, true
}
// SetMission sets field value
func (o *BackgroundResponse) SetMission(v string) {
o.Mission = v
}
// GetBackground returns the Background field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *BackgroundResponse) GetBackground() string {
if o == nil || IsNil(o.Background.Get()) {
var ret string
return ret
}
return *o.Background.Get()
}
// GetBackgroundOk returns a tuple with the Background field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *BackgroundResponse) GetBackgroundOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Background.Get(), o.Background.IsSet()
}
// HasBackground returns a boolean if a field has been set.
func (o *BackgroundResponse) HasBackground() bool {
if o != nil && o.Background.IsSet() {
return true
}
return false
}
// SetBackground gets a reference to the given NullableString and assigns it to the Background field.
func (o *BackgroundResponse) SetBackground(v string) {
o.Background.Set(&v)
}
// SetBackgroundNil sets the value for Background to be an explicit nil
func (o *BackgroundResponse) SetBackgroundNil() {
o.Background.Set(nil)
}
// UnsetBackground ensures that no value is present for Background, not even an explicit nil
func (o *BackgroundResponse) UnsetBackground() {
o.Background.Unset()
}
// GetDisposition returns the Disposition field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *BackgroundResponse) GetDisposition() DispositionTraits {
if o == nil || IsNil(o.Disposition.Get()) {
var ret DispositionTraits
return ret
}
return *o.Disposition.Get()
}
// GetDispositionOk returns a tuple with the Disposition field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *BackgroundResponse) GetDispositionOk() (*DispositionTraits, bool) {
if o == nil {
return nil, false
}
return o.Disposition.Get(), o.Disposition.IsSet()
}
// HasDisposition returns a boolean if a field has been set.
func (o *BackgroundResponse) HasDisposition() bool {
if o != nil && o.Disposition.IsSet() {
return true
}
return false
}
// SetDisposition gets a reference to the given NullableDispositionTraits and assigns it to the Disposition field.
func (o *BackgroundResponse) SetDisposition(v DispositionTraits) {
o.Disposition.Set(&v)
}
// SetDispositionNil sets the value for Disposition to be an explicit nil
func (o *BackgroundResponse) SetDispositionNil() {
o.Disposition.Set(nil)
}
// UnsetDisposition ensures that no value is present for Disposition, not even an explicit nil
func (o *BackgroundResponse) UnsetDisposition() {
o.Disposition.Unset()
}
func (o BackgroundResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o BackgroundResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["mission"] = o.Mission
if o.Background.IsSet() {
toSerialize["background"] = o.Background.Get()
}
if o.Disposition.IsSet() {
toSerialize["disposition"] = o.Disposition.Get()
}
return toSerialize, nil
}
func (o *BackgroundResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"mission",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varBackgroundResponse := _BackgroundResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varBackgroundResponse)
if err != nil {
return err
}
*o = BackgroundResponse(varBackgroundResponse)
return err
}
type NullableBackgroundResponse struct {
value *BackgroundResponse
isSet bool
}
func (v NullableBackgroundResponse) Get() *BackgroundResponse {
return v.value
}
func (v *NullableBackgroundResponse) Set(val *BackgroundResponse) {
v.value = val
v.isSet = true
}
func (v NullableBackgroundResponse) IsSet() bool {
return v.isSet
}
func (v *NullableBackgroundResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBackgroundResponse(val *BackgroundResponse) *NullableBackgroundResponse {
return &NullableBackgroundResponse{value: val, isSet: true}
}
func (v NullableBackgroundResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBackgroundResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,217 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the BankConfigResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &BankConfigResponse{}
// BankConfigResponse Response model for bank configuration.
type BankConfigResponse struct {
// Bank identifier
BankId string `json:"bank_id"`
// Fully resolved configuration with all hierarchical overrides applied (Python field names)
Config map[string]interface{} `json:"config"`
// Bank-specific configuration overrides only (Python field names)
Overrides map[string]interface{} `json:"overrides"`
}
type _BankConfigResponse BankConfigResponse
// NewBankConfigResponse instantiates a new BankConfigResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBankConfigResponse(bankId string, config map[string]interface{}, overrides map[string]interface{}) *BankConfigResponse {
this := BankConfigResponse{}
this.BankId = bankId
this.Config = config
this.Overrides = overrides
return &this
}
// NewBankConfigResponseWithDefaults instantiates a new BankConfigResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBankConfigResponseWithDefaults() *BankConfigResponse {
this := BankConfigResponse{}
return &this
}
// GetBankId returns the BankId field value
func (o *BankConfigResponse) GetBankId() string {
if o == nil {
var ret string
return ret
}
return o.BankId
}
// GetBankIdOk returns a tuple with the BankId field value
// and a boolean to check if the value has been set.
func (o *BankConfigResponse) GetBankIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.BankId, true
}
// SetBankId sets field value
func (o *BankConfigResponse) SetBankId(v string) {
o.BankId = v
}
// GetConfig returns the Config field value
func (o *BankConfigResponse) GetConfig() map[string]interface{} {
if o == nil {
var ret map[string]interface{}
return ret
}
return o.Config
}
// GetConfigOk returns a tuple with the Config field value
// and a boolean to check if the value has been set.
func (o *BankConfigResponse) GetConfigOk() (map[string]interface{}, bool) {
if o == nil {
return map[string]interface{}{}, false
}
return o.Config, true
}
// SetConfig sets field value
func (o *BankConfigResponse) SetConfig(v map[string]interface{}) {
o.Config = v
}
// GetOverrides returns the Overrides field value
func (o *BankConfigResponse) GetOverrides() map[string]interface{} {
if o == nil {
var ret map[string]interface{}
return ret
}
return o.Overrides
}
// GetOverridesOk returns a tuple with the Overrides field value
// and a boolean to check if the value has been set.
func (o *BankConfigResponse) GetOverridesOk() (map[string]interface{}, bool) {
if o == nil {
return map[string]interface{}{}, false
}
return o.Overrides, true
}
// SetOverrides sets field value
func (o *BankConfigResponse) SetOverrides(v map[string]interface{}) {
o.Overrides = v
}
func (o BankConfigResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o BankConfigResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["bank_id"] = o.BankId
toSerialize["config"] = o.Config
toSerialize["overrides"] = o.Overrides
return toSerialize, nil
}
func (o *BankConfigResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"bank_id",
"config",
"overrides",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varBankConfigResponse := _BankConfigResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varBankConfigResponse)
if err != nil {
return err
}
*o = BankConfigResponse(varBankConfigResponse)
return err
}
type NullableBankConfigResponse struct {
value *BankConfigResponse
isSet bool
}
func (v NullableBankConfigResponse) Get() *BankConfigResponse {
return v.value
}
func (v *NullableBankConfigResponse) Set(val *BankConfigResponse) {
v.value = val
v.isSet = true
}
func (v NullableBankConfigResponse) IsSet() bool {
return v.isSet
}
func (v *NullableBankConfigResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBankConfigResponse(val *BankConfigResponse) *NullableBankConfigResponse {
return &NullableBankConfigResponse{value: val, isSet: true}
}
func (v NullableBankConfigResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBankConfigResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,159 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the BankConfigUpdate type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &BankConfigUpdate{}
// BankConfigUpdate Request model for updating bank configuration.
type BankConfigUpdate struct {
// Configuration overrides. Keys can be in Python field format (llm_provider) or environment variable format (HINDSIGHT_API_LLM_PROVIDER). Only hierarchical fields can be overridden per-bank.
Updates map[string]interface{} `json:"updates"`
}
type _BankConfigUpdate BankConfigUpdate
// NewBankConfigUpdate instantiates a new BankConfigUpdate object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBankConfigUpdate(updates map[string]interface{}) *BankConfigUpdate {
this := BankConfigUpdate{}
this.Updates = updates
return &this
}
// NewBankConfigUpdateWithDefaults instantiates a new BankConfigUpdate object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBankConfigUpdateWithDefaults() *BankConfigUpdate {
this := BankConfigUpdate{}
return &this
}
// GetUpdates returns the Updates field value
func (o *BankConfigUpdate) GetUpdates() map[string]interface{} {
if o == nil {
var ret map[string]interface{}
return ret
}
return o.Updates
}
// GetUpdatesOk returns a tuple with the Updates field value
// and a boolean to check if the value has been set.
func (o *BankConfigUpdate) GetUpdatesOk() (map[string]interface{}, bool) {
if o == nil {
return map[string]interface{}{}, false
}
return o.Updates, true
}
// SetUpdates sets field value
func (o *BankConfigUpdate) SetUpdates(v map[string]interface{}) {
o.Updates = v
}
func (o BankConfigUpdate) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o BankConfigUpdate) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["updates"] = o.Updates
return toSerialize, nil
}
func (o *BankConfigUpdate) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"updates",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varBankConfigUpdate := _BankConfigUpdate{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varBankConfigUpdate)
if err != nil {
return err
}
*o = BankConfigUpdate(varBankConfigUpdate)
return err
}
type NullableBankConfigUpdate struct {
value *BankConfigUpdate
isSet bool
}
func (v NullableBankConfigUpdate) Get() *BankConfigUpdate {
return v.value
}
func (v *NullableBankConfigUpdate) Set(val *BankConfigUpdate) {
v.value = val
v.isSet = true
}
func (v NullableBankConfigUpdate) IsSet() bool {
return v.isSet
}
func (v *NullableBankConfigUpdate) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBankConfigUpdate(val *BankConfigUpdate) *NullableBankConfigUpdate {
return &NullableBankConfigUpdate{value: val, isSet: true}
}
func (v NullableBankConfigUpdate) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBankConfigUpdate) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,370 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the BankListItem type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &BankListItem{}
// BankListItem Bank list item with profile summary.
type BankListItem struct {
BankId string `json:"bank_id"`
Name NullableString `json:"name,omitempty"`
Disposition DispositionTraits `json:"disposition"`
Mission NullableString `json:"mission,omitempty"`
CreatedAt NullableString `json:"created_at,omitempty"`
UpdatedAt NullableString `json:"updated_at,omitempty"`
}
type _BankListItem BankListItem
// NewBankListItem instantiates a new BankListItem object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBankListItem(bankId string, disposition DispositionTraits) *BankListItem {
this := BankListItem{}
this.BankId = bankId
this.Disposition = disposition
return &this
}
// NewBankListItemWithDefaults instantiates a new BankListItem object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBankListItemWithDefaults() *BankListItem {
this := BankListItem{}
return &this
}
// GetBankId returns the BankId field value
func (o *BankListItem) GetBankId() string {
if o == nil {
var ret string
return ret
}
return o.BankId
}
// GetBankIdOk returns a tuple with the BankId field value
// and a boolean to check if the value has been set.
func (o *BankListItem) GetBankIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.BankId, true
}
// SetBankId sets field value
func (o *BankListItem) SetBankId(v string) {
o.BankId = v
}
// GetName returns the Name field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *BankListItem) GetName() string {
if o == nil || IsNil(o.Name.Get()) {
var ret string
return ret
}
return *o.Name.Get()
}
// GetNameOk returns a tuple with the Name field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *BankListItem) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Name.Get(), o.Name.IsSet()
}
// HasName returns a boolean if a field has been set.
func (o *BankListItem) HasName() bool {
if o != nil && o.Name.IsSet() {
return true
}
return false
}
// SetName gets a reference to the given NullableString and assigns it to the Name field.
func (o *BankListItem) SetName(v string) {
o.Name.Set(&v)
}
// SetNameNil sets the value for Name to be an explicit nil
func (o *BankListItem) SetNameNil() {
o.Name.Set(nil)
}
// UnsetName ensures that no value is present for Name, not even an explicit nil
func (o *BankListItem) UnsetName() {
o.Name.Unset()
}
// GetDisposition returns the Disposition field value
func (o *BankListItem) GetDisposition() DispositionTraits {
if o == nil {
var ret DispositionTraits
return ret
}
return o.Disposition
}
// GetDispositionOk returns a tuple with the Disposition field value
// and a boolean to check if the value has been set.
func (o *BankListItem) GetDispositionOk() (*DispositionTraits, bool) {
if o == nil {
return nil, false
}
return &o.Disposition, true
}
// SetDisposition sets field value
func (o *BankListItem) SetDisposition(v DispositionTraits) {
o.Disposition = v
}
// GetMission returns the Mission field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *BankListItem) GetMission() string {
if o == nil || IsNil(o.Mission.Get()) {
var ret string
return ret
}
return *o.Mission.Get()
}
// GetMissionOk returns a tuple with the Mission field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *BankListItem) GetMissionOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Mission.Get(), o.Mission.IsSet()
}
// HasMission returns a boolean if a field has been set.
func (o *BankListItem) HasMission() bool {
if o != nil && o.Mission.IsSet() {
return true
}
return false
}
// SetMission gets a reference to the given NullableString and assigns it to the Mission field.
func (o *BankListItem) SetMission(v string) {
o.Mission.Set(&v)
}
// SetMissionNil sets the value for Mission to be an explicit nil
func (o *BankListItem) SetMissionNil() {
o.Mission.Set(nil)
}
// UnsetMission ensures that no value is present for Mission, not even an explicit nil
func (o *BankListItem) UnsetMission() {
o.Mission.Unset()
}
// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *BankListItem) GetCreatedAt() string {
if o == nil || IsNil(o.CreatedAt.Get()) {
var ret string
return ret
}
return *o.CreatedAt.Get()
}
// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *BankListItem) GetCreatedAtOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.CreatedAt.Get(), o.CreatedAt.IsSet()
}
// HasCreatedAt returns a boolean if a field has been set.
func (o *BankListItem) HasCreatedAt() bool {
if o != nil && o.CreatedAt.IsSet() {
return true
}
return false
}
// SetCreatedAt gets a reference to the given NullableString and assigns it to the CreatedAt field.
func (o *BankListItem) SetCreatedAt(v string) {
o.CreatedAt.Set(&v)
}
// SetCreatedAtNil sets the value for CreatedAt to be an explicit nil
func (o *BankListItem) SetCreatedAtNil() {
o.CreatedAt.Set(nil)
}
// UnsetCreatedAt ensures that no value is present for CreatedAt, not even an explicit nil
func (o *BankListItem) UnsetCreatedAt() {
o.CreatedAt.Unset()
}
// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *BankListItem) GetUpdatedAt() string {
if o == nil || IsNil(o.UpdatedAt.Get()) {
var ret string
return ret
}
return *o.UpdatedAt.Get()
}
// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *BankListItem) GetUpdatedAtOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.UpdatedAt.Get(), o.UpdatedAt.IsSet()
}
// HasUpdatedAt returns a boolean if a field has been set.
func (o *BankListItem) HasUpdatedAt() bool {
if o != nil && o.UpdatedAt.IsSet() {
return true
}
return false
}
// SetUpdatedAt gets a reference to the given NullableString and assigns it to the UpdatedAt field.
func (o *BankListItem) SetUpdatedAt(v string) {
o.UpdatedAt.Set(&v)
}
// SetUpdatedAtNil sets the value for UpdatedAt to be an explicit nil
func (o *BankListItem) SetUpdatedAtNil() {
o.UpdatedAt.Set(nil)
}
// UnsetUpdatedAt ensures that no value is present for UpdatedAt, not even an explicit nil
func (o *BankListItem) UnsetUpdatedAt() {
o.UpdatedAt.Unset()
}
func (o BankListItem) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o BankListItem) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["bank_id"] = o.BankId
if o.Name.IsSet() {
toSerialize["name"] = o.Name.Get()
}
toSerialize["disposition"] = o.Disposition
if o.Mission.IsSet() {
toSerialize["mission"] = o.Mission.Get()
}
if o.CreatedAt.IsSet() {
toSerialize["created_at"] = o.CreatedAt.Get()
}
if o.UpdatedAt.IsSet() {
toSerialize["updated_at"] = o.UpdatedAt.Get()
}
return toSerialize, nil
}
func (o *BankListItem) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"bank_id",
"disposition",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varBankListItem := _BankListItem{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varBankListItem)
if err != nil {
return err
}
*o = BankListItem(varBankListItem)
return err
}
type NullableBankListItem struct {
value *BankListItem
isSet bool
}
func (v NullableBankListItem) Get() *BankListItem {
return v.value
}
func (v *NullableBankListItem) Set(val *BankListItem) {
v.value = val
v.isSet = true
}
func (v NullableBankListItem) IsSet() bool {
return v.isSet
}
func (v *NullableBankListItem) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBankListItem(val *BankListItem) *NullableBankListItem {
return &NullableBankListItem{value: val, isSet: true}
}
func (v NullableBankListItem) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBankListItem) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,158 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the BankListResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &BankListResponse{}
// BankListResponse Response model for listing all banks.
type BankListResponse struct {
Banks []BankListItem `json:"banks"`
}
type _BankListResponse BankListResponse
// NewBankListResponse instantiates a new BankListResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBankListResponse(banks []BankListItem) *BankListResponse {
this := BankListResponse{}
this.Banks = banks
return &this
}
// NewBankListResponseWithDefaults instantiates a new BankListResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBankListResponseWithDefaults() *BankListResponse {
this := BankListResponse{}
return &this
}
// GetBanks returns the Banks field value
func (o *BankListResponse) GetBanks() []BankListItem {
if o == nil {
var ret []BankListItem
return ret
}
return o.Banks
}
// GetBanksOk returns a tuple with the Banks field value
// and a boolean to check if the value has been set.
func (o *BankListResponse) GetBanksOk() ([]BankListItem, bool) {
if o == nil {
return nil, false
}
return o.Banks, true
}
// SetBanks sets field value
func (o *BankListResponse) SetBanks(v []BankListItem) {
o.Banks = v
}
func (o BankListResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o BankListResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["banks"] = o.Banks
return toSerialize, nil
}
func (o *BankListResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"banks",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varBankListResponse := _BankListResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varBankListResponse)
if err != nil {
return err
}
*o = BankListResponse(varBankListResponse)
return err
}
type NullableBankListResponse struct {
value *BankListResponse
isSet bool
}
func (v NullableBankListResponse) Get() *BankListResponse {
return v.value
}
func (v *NullableBankListResponse) Set(val *BankListResponse) {
v.value = val
v.isSet = true
}
func (v NullableBankListResponse) IsSet() bool {
return v.isSet
}
func (v *NullableBankListResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBankListResponse(val *BankListResponse) *NullableBankListResponse {
return &NullableBankListResponse{value: val, isSet: true}
}
func (v NullableBankListResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBankListResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,289 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the BankProfileResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &BankProfileResponse{}
// BankProfileResponse Response model for bank profile.
type BankProfileResponse struct {
BankId string `json:"bank_id"`
Name string `json:"name"`
Disposition DispositionTraits `json:"disposition"`
// The agent's mission - who they are and what they're trying to accomplish
Mission string `json:"mission"`
Background NullableString `json:"background,omitempty"`
}
type _BankProfileResponse BankProfileResponse
// NewBankProfileResponse instantiates a new BankProfileResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBankProfileResponse(bankId string, name string, disposition DispositionTraits, mission string) *BankProfileResponse {
this := BankProfileResponse{}
this.BankId = bankId
this.Name = name
this.Disposition = disposition
this.Mission = mission
return &this
}
// NewBankProfileResponseWithDefaults instantiates a new BankProfileResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBankProfileResponseWithDefaults() *BankProfileResponse {
this := BankProfileResponse{}
return &this
}
// GetBankId returns the BankId field value
func (o *BankProfileResponse) GetBankId() string {
if o == nil {
var ret string
return ret
}
return o.BankId
}
// GetBankIdOk returns a tuple with the BankId field value
// and a boolean to check if the value has been set.
func (o *BankProfileResponse) GetBankIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.BankId, true
}
// SetBankId sets field value
func (o *BankProfileResponse) SetBankId(v string) {
o.BankId = v
}
// GetName returns the Name field value
func (o *BankProfileResponse) GetName() string {
if o == nil {
var ret string
return ret
}
return o.Name
}
// GetNameOk returns a tuple with the Name field value
// and a boolean to check if the value has been set.
func (o *BankProfileResponse) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Name, true
}
// SetName sets field value
func (o *BankProfileResponse) SetName(v string) {
o.Name = v
}
// GetDisposition returns the Disposition field value
func (o *BankProfileResponse) GetDisposition() DispositionTraits {
if o == nil {
var ret DispositionTraits
return ret
}
return o.Disposition
}
// GetDispositionOk returns a tuple with the Disposition field value
// and a boolean to check if the value has been set.
func (o *BankProfileResponse) GetDispositionOk() (*DispositionTraits, bool) {
if o == nil {
return nil, false
}
return &o.Disposition, true
}
// SetDisposition sets field value
func (o *BankProfileResponse) SetDisposition(v DispositionTraits) {
o.Disposition = v
}
// GetMission returns the Mission field value
func (o *BankProfileResponse) GetMission() string {
if o == nil {
var ret string
return ret
}
return o.Mission
}
// GetMissionOk returns a tuple with the Mission field value
// and a boolean to check if the value has been set.
func (o *BankProfileResponse) GetMissionOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Mission, true
}
// SetMission sets field value
func (o *BankProfileResponse) SetMission(v string) {
o.Mission = v
}
// GetBackground returns the Background field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *BankProfileResponse) GetBackground() string {
if o == nil || IsNil(o.Background.Get()) {
var ret string
return ret
}
return *o.Background.Get()
}
// GetBackgroundOk returns a tuple with the Background field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *BankProfileResponse) GetBackgroundOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Background.Get(), o.Background.IsSet()
}
// HasBackground returns a boolean if a field has been set.
func (o *BankProfileResponse) HasBackground() bool {
if o != nil && o.Background.IsSet() {
return true
}
return false
}
// SetBackground gets a reference to the given NullableString and assigns it to the Background field.
func (o *BankProfileResponse) SetBackground(v string) {
o.Background.Set(&v)
}
// SetBackgroundNil sets the value for Background to be an explicit nil
func (o *BankProfileResponse) SetBackgroundNil() {
o.Background.Set(nil)
}
// UnsetBackground ensures that no value is present for Background, not even an explicit nil
func (o *BankProfileResponse) UnsetBackground() {
o.Background.Unset()
}
func (o BankProfileResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o BankProfileResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["bank_id"] = o.BankId
toSerialize["name"] = o.Name
toSerialize["disposition"] = o.Disposition
toSerialize["mission"] = o.Mission
if o.Background.IsSet() {
toSerialize["background"] = o.Background.Get()
}
return toSerialize, nil
}
func (o *BankProfileResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"bank_id",
"name",
"disposition",
"mission",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varBankProfileResponse := _BankProfileResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varBankProfileResponse)
if err != nil {
return err
}
*o = BankProfileResponse(varBankProfileResponse)
return err
}
type NullableBankProfileResponse struct {
value *BankProfileResponse
isSet bool
}
func (v NullableBankProfileResponse) Get() *BankProfileResponse {
return v.value
}
func (v *NullableBankProfileResponse) Set(val *BankProfileResponse) {
v.value = val
v.isSet = true
}
func (v NullableBankProfileResponse) IsSet() bool {
return v.isSet
}
func (v *NullableBankProfileResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBankProfileResponse(val *BankProfileResponse) *NullableBankProfileResponse {
return &NullableBankProfileResponse{value: val, isSet: true}
}
func (v NullableBankProfileResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBankProfileResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,538 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the BankStatsResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &BankStatsResponse{}
// BankStatsResponse Response model for bank statistics endpoint.
type BankStatsResponse struct {
BankId string `json:"bank_id"`
TotalNodes int32 `json:"total_nodes"`
TotalLinks int32 `json:"total_links"`
TotalDocuments int32 `json:"total_documents"`
NodesByFactType map[string]int32 `json:"nodes_by_fact_type"`
LinksByLinkType map[string]int32 `json:"links_by_link_type"`
LinksByFactType map[string]int32 `json:"links_by_fact_type"`
LinksBreakdown map[string]map[string]int32 `json:"links_breakdown"`
PendingOperations int32 `json:"pending_operations"`
FailedOperations int32 `json:"failed_operations"`
LastConsolidatedAt NullableString `json:"last_consolidated_at,omitempty"`
// Number of memories not yet processed into observations
PendingConsolidation *int32 `json:"pending_consolidation,omitempty"`
// Total number of observations
TotalObservations *int32 `json:"total_observations,omitempty"`
}
type _BankStatsResponse BankStatsResponse
// NewBankStatsResponse instantiates a new BankStatsResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBankStatsResponse(bankId string, totalNodes int32, totalLinks int32, totalDocuments int32, nodesByFactType map[string]int32, linksByLinkType map[string]int32, linksByFactType map[string]int32, linksBreakdown map[string]map[string]int32, pendingOperations int32, failedOperations int32) *BankStatsResponse {
this := BankStatsResponse{}
this.BankId = bankId
this.TotalNodes = totalNodes
this.TotalLinks = totalLinks
this.TotalDocuments = totalDocuments
this.NodesByFactType = nodesByFactType
this.LinksByLinkType = linksByLinkType
this.LinksByFactType = linksByFactType
this.LinksBreakdown = linksBreakdown
this.PendingOperations = pendingOperations
this.FailedOperations = failedOperations
var pendingConsolidation int32 = 0
this.PendingConsolidation = &pendingConsolidation
var totalObservations int32 = 0
this.TotalObservations = &totalObservations
return &this
}
// NewBankStatsResponseWithDefaults instantiates a new BankStatsResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBankStatsResponseWithDefaults() *BankStatsResponse {
this := BankStatsResponse{}
var pendingConsolidation int32 = 0
this.PendingConsolidation = &pendingConsolidation
var totalObservations int32 = 0
this.TotalObservations = &totalObservations
return &this
}
// GetBankId returns the BankId field value
func (o *BankStatsResponse) GetBankId() string {
if o == nil {
var ret string
return ret
}
return o.BankId
}
// GetBankIdOk returns a tuple with the BankId field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetBankIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.BankId, true
}
// SetBankId sets field value
func (o *BankStatsResponse) SetBankId(v string) {
o.BankId = v
}
// GetTotalNodes returns the TotalNodes field value
func (o *BankStatsResponse) GetTotalNodes() int32 {
if o == nil {
var ret int32
return ret
}
return o.TotalNodes
}
// GetTotalNodesOk returns a tuple with the TotalNodes field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetTotalNodesOk() (*int32, bool) {
if o == nil {
return nil, false
}
return &o.TotalNodes, true
}
// SetTotalNodes sets field value
func (o *BankStatsResponse) SetTotalNodes(v int32) {
o.TotalNodes = v
}
// GetTotalLinks returns the TotalLinks field value
func (o *BankStatsResponse) GetTotalLinks() int32 {
if o == nil {
var ret int32
return ret
}
return o.TotalLinks
}
// GetTotalLinksOk returns a tuple with the TotalLinks field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetTotalLinksOk() (*int32, bool) {
if o == nil {
return nil, false
}
return &o.TotalLinks, true
}
// SetTotalLinks sets field value
func (o *BankStatsResponse) SetTotalLinks(v int32) {
o.TotalLinks = v
}
// GetTotalDocuments returns the TotalDocuments field value
func (o *BankStatsResponse) GetTotalDocuments() int32 {
if o == nil {
var ret int32
return ret
}
return o.TotalDocuments
}
// GetTotalDocumentsOk returns a tuple with the TotalDocuments field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetTotalDocumentsOk() (*int32, bool) {
if o == nil {
return nil, false
}
return &o.TotalDocuments, true
}
// SetTotalDocuments sets field value
func (o *BankStatsResponse) SetTotalDocuments(v int32) {
o.TotalDocuments = v
}
// GetNodesByFactType returns the NodesByFactType field value
func (o *BankStatsResponse) GetNodesByFactType() map[string]int32 {
if o == nil {
var ret map[string]int32
return ret
}
return o.NodesByFactType
}
// GetNodesByFactTypeOk returns a tuple with the NodesByFactType field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetNodesByFactTypeOk() (map[string]int32, bool) {
if o == nil {
return map[string]int32{}, false
}
return o.NodesByFactType, true
}
// SetNodesByFactType sets field value
func (o *BankStatsResponse) SetNodesByFactType(v map[string]int32) {
o.NodesByFactType = v
}
// GetLinksByLinkType returns the LinksByLinkType field value
func (o *BankStatsResponse) GetLinksByLinkType() map[string]int32 {
if o == nil {
var ret map[string]int32
return ret
}
return o.LinksByLinkType
}
// GetLinksByLinkTypeOk returns a tuple with the LinksByLinkType field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetLinksByLinkTypeOk() (map[string]int32, bool) {
if o == nil {
return map[string]int32{}, false
}
return o.LinksByLinkType, true
}
// SetLinksByLinkType sets field value
func (o *BankStatsResponse) SetLinksByLinkType(v map[string]int32) {
o.LinksByLinkType = v
}
// GetLinksByFactType returns the LinksByFactType field value
func (o *BankStatsResponse) GetLinksByFactType() map[string]int32 {
if o == nil {
var ret map[string]int32
return ret
}
return o.LinksByFactType
}
// GetLinksByFactTypeOk returns a tuple with the LinksByFactType field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetLinksByFactTypeOk() (map[string]int32, bool) {
if o == nil {
return map[string]int32{}, false
}
return o.LinksByFactType, true
}
// SetLinksByFactType sets field value
func (o *BankStatsResponse) SetLinksByFactType(v map[string]int32) {
o.LinksByFactType = v
}
// GetLinksBreakdown returns the LinksBreakdown field value
func (o *BankStatsResponse) GetLinksBreakdown() map[string]map[string]int32 {
if o == nil {
var ret map[string]map[string]int32
return ret
}
return o.LinksBreakdown
}
// GetLinksBreakdownOk returns a tuple with the LinksBreakdown field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetLinksBreakdownOk() (map[string]map[string]int32, bool) {
if o == nil {
return map[string]map[string]int32{}, false
}
return o.LinksBreakdown, true
}
// SetLinksBreakdown sets field value
func (o *BankStatsResponse) SetLinksBreakdown(v map[string]map[string]int32) {
o.LinksBreakdown = v
}
// GetPendingOperations returns the PendingOperations field value
func (o *BankStatsResponse) GetPendingOperations() int32 {
if o == nil {
var ret int32
return ret
}
return o.PendingOperations
}
// GetPendingOperationsOk returns a tuple with the PendingOperations field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetPendingOperationsOk() (*int32, bool) {
if o == nil {
return nil, false
}
return &o.PendingOperations, true
}
// SetPendingOperations sets field value
func (o *BankStatsResponse) SetPendingOperations(v int32) {
o.PendingOperations = v
}
// GetFailedOperations returns the FailedOperations field value
func (o *BankStatsResponse) GetFailedOperations() int32 {
if o == nil {
var ret int32
return ret
}
return o.FailedOperations
}
// GetFailedOperationsOk returns a tuple with the FailedOperations field value
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetFailedOperationsOk() (*int32, bool) {
if o == nil {
return nil, false
}
return &o.FailedOperations, true
}
// SetFailedOperations sets field value
func (o *BankStatsResponse) SetFailedOperations(v int32) {
o.FailedOperations = v
}
// GetLastConsolidatedAt returns the LastConsolidatedAt field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *BankStatsResponse) GetLastConsolidatedAt() string {
if o == nil || IsNil(o.LastConsolidatedAt.Get()) {
var ret string
return ret
}
return *o.LastConsolidatedAt.Get()
}
// GetLastConsolidatedAtOk returns a tuple with the LastConsolidatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *BankStatsResponse) GetLastConsolidatedAtOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.LastConsolidatedAt.Get(), o.LastConsolidatedAt.IsSet()
}
// HasLastConsolidatedAt returns a boolean if a field has been set.
func (o *BankStatsResponse) HasLastConsolidatedAt() bool {
if o != nil && o.LastConsolidatedAt.IsSet() {
return true
}
return false
}
// SetLastConsolidatedAt gets a reference to the given NullableString and assigns it to the LastConsolidatedAt field.
func (o *BankStatsResponse) SetLastConsolidatedAt(v string) {
o.LastConsolidatedAt.Set(&v)
}
// SetLastConsolidatedAtNil sets the value for LastConsolidatedAt to be an explicit nil
func (o *BankStatsResponse) SetLastConsolidatedAtNil() {
o.LastConsolidatedAt.Set(nil)
}
// UnsetLastConsolidatedAt ensures that no value is present for LastConsolidatedAt, not even an explicit nil
func (o *BankStatsResponse) UnsetLastConsolidatedAt() {
o.LastConsolidatedAt.Unset()
}
// GetPendingConsolidation returns the PendingConsolidation field value if set, zero value otherwise.
func (o *BankStatsResponse) GetPendingConsolidation() int32 {
if o == nil || IsNil(o.PendingConsolidation) {
var ret int32
return ret
}
return *o.PendingConsolidation
}
// GetPendingConsolidationOk returns a tuple with the PendingConsolidation field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetPendingConsolidationOk() (*int32, bool) {
if o == nil || IsNil(o.PendingConsolidation) {
return nil, false
}
return o.PendingConsolidation, true
}
// HasPendingConsolidation returns a boolean if a field has been set.
func (o *BankStatsResponse) HasPendingConsolidation() bool {
if o != nil && !IsNil(o.PendingConsolidation) {
return true
}
return false
}
// SetPendingConsolidation gets a reference to the given int32 and assigns it to the PendingConsolidation field.
func (o *BankStatsResponse) SetPendingConsolidation(v int32) {
o.PendingConsolidation = &v
}
// GetTotalObservations returns the TotalObservations field value if set, zero value otherwise.
func (o *BankStatsResponse) GetTotalObservations() int32 {
if o == nil || IsNil(o.TotalObservations) {
var ret int32
return ret
}
return *o.TotalObservations
}
// GetTotalObservationsOk returns a tuple with the TotalObservations field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *BankStatsResponse) GetTotalObservationsOk() (*int32, bool) {
if o == nil || IsNil(o.TotalObservations) {
return nil, false
}
return o.TotalObservations, true
}
// HasTotalObservations returns a boolean if a field has been set.
func (o *BankStatsResponse) HasTotalObservations() bool {
if o != nil && !IsNil(o.TotalObservations) {
return true
}
return false
}
// SetTotalObservations gets a reference to the given int32 and assigns it to the TotalObservations field.
func (o *BankStatsResponse) SetTotalObservations(v int32) {
o.TotalObservations = &v
}
func (o BankStatsResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o BankStatsResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["bank_id"] = o.BankId
toSerialize["total_nodes"] = o.TotalNodes
toSerialize["total_links"] = o.TotalLinks
toSerialize["total_documents"] = o.TotalDocuments
toSerialize["nodes_by_fact_type"] = o.NodesByFactType
toSerialize["links_by_link_type"] = o.LinksByLinkType
toSerialize["links_by_fact_type"] = o.LinksByFactType
toSerialize["links_breakdown"] = o.LinksBreakdown
toSerialize["pending_operations"] = o.PendingOperations
toSerialize["failed_operations"] = o.FailedOperations
if o.LastConsolidatedAt.IsSet() {
toSerialize["last_consolidated_at"] = o.LastConsolidatedAt.Get()
}
if !IsNil(o.PendingConsolidation) {
toSerialize["pending_consolidation"] = o.PendingConsolidation
}
if !IsNil(o.TotalObservations) {
toSerialize["total_observations"] = o.TotalObservations
}
return toSerialize, nil
}
func (o *BankStatsResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"bank_id",
"total_nodes",
"total_links",
"total_documents",
"nodes_by_fact_type",
"links_by_link_type",
"links_by_fact_type",
"links_breakdown",
"pending_operations",
"failed_operations",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varBankStatsResponse := _BankStatsResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varBankStatsResponse)
if err != nil {
return err
}
*o = BankStatsResponse(varBankStatsResponse)
return err
}
type NullableBankStatsResponse struct {
value *BankStatsResponse
isSet bool
}
func (v NullableBankStatsResponse) Get() *BankStatsResponse {
return v.value
}
func (v *NullableBankStatsResponse) Set(val *BankStatsResponse) {
v.value = val
v.isSet = true
}
func (v NullableBankStatsResponse) IsSet() bool {
return v.isSet
}
func (v *NullableBankStatsResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBankStatsResponse(val *BankStatsResponse) *NullableBankStatsResponse {
return &NullableBankStatsResponse{value: val, isSet: true}
}
func (v NullableBankStatsResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBankStatsResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
-113
View File
@@ -1,113 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"fmt"
)
// Budget Budget levels for recall/reflect operations.
type Budget string
// List of Budget
const (
LOW Budget = "low"
MID Budget = "mid"
HIGH Budget = "high"
)
// All allowed values of Budget enum
var AllowedBudgetEnumValues = []Budget{
"low",
"mid",
"high",
}
func (v *Budget) UnmarshalJSON(src []byte) error {
var value string
err := json.Unmarshal(src, &value)
if err != nil {
return err
}
enumTypeValue := Budget(value)
for _, existing := range AllowedBudgetEnumValues {
if existing == enumTypeValue {
*v = enumTypeValue
return nil
}
}
return fmt.Errorf("%+v is not a valid Budget", value)
}
// NewBudgetFromValue returns a pointer to a valid Budget
// for the value passed as argument, or an error if the value passed is not allowed by the enum
func NewBudgetFromValue(v string) (*Budget, error) {
ev := Budget(v)
if ev.IsValid() {
return &ev, nil
} else {
return nil, fmt.Errorf("invalid value '%v' for Budget: valid values are %v", v, AllowedBudgetEnumValues)
}
}
// IsValid return true if the value is valid for the enum, false otherwise
func (v Budget) IsValid() bool {
for _, existing := range AllowedBudgetEnumValues {
if existing == v {
return true
}
}
return false
}
// Ptr returns reference to Budget value
func (v Budget) Ptr() *Budget {
return &v
}
type NullableBudget struct {
value *Budget
isSet bool
}
func (v NullableBudget) Get() *Budget {
return v.value
}
func (v *NullableBudget) Set(val *Budget) {
v.value = val
v.isSet = true
}
func (v NullableBudget) IsSet() bool {
return v.isSet
}
func (v *NullableBudget) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBudget(val *Budget) *NullableBudget {
return &NullableBudget{value: val, isSet: true}
}
func (v NullableBudget) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBudget) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,214 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the CancelOperationResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &CancelOperationResponse{}
// CancelOperationResponse Response model for cancel operation endpoint.
type CancelOperationResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
OperationId string `json:"operation_id"`
}
type _CancelOperationResponse CancelOperationResponse
// NewCancelOperationResponse instantiates a new CancelOperationResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewCancelOperationResponse(success bool, message string, operationId string) *CancelOperationResponse {
this := CancelOperationResponse{}
this.Success = success
this.Message = message
this.OperationId = operationId
return &this
}
// NewCancelOperationResponseWithDefaults instantiates a new CancelOperationResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewCancelOperationResponseWithDefaults() *CancelOperationResponse {
this := CancelOperationResponse{}
return &this
}
// GetSuccess returns the Success field value
func (o *CancelOperationResponse) GetSuccess() bool {
if o == nil {
var ret bool
return ret
}
return o.Success
}
// GetSuccessOk returns a tuple with the Success field value
// and a boolean to check if the value has been set.
func (o *CancelOperationResponse) GetSuccessOk() (*bool, bool) {
if o == nil {
return nil, false
}
return &o.Success, true
}
// SetSuccess sets field value
func (o *CancelOperationResponse) SetSuccess(v bool) {
o.Success = v
}
// GetMessage returns the Message field value
func (o *CancelOperationResponse) GetMessage() string {
if o == nil {
var ret string
return ret
}
return o.Message
}
// GetMessageOk returns a tuple with the Message field value
// and a boolean to check if the value has been set.
func (o *CancelOperationResponse) GetMessageOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Message, true
}
// SetMessage sets field value
func (o *CancelOperationResponse) SetMessage(v string) {
o.Message = v
}
// GetOperationId returns the OperationId field value
func (o *CancelOperationResponse) GetOperationId() string {
if o == nil {
var ret string
return ret
}
return o.OperationId
}
// GetOperationIdOk returns a tuple with the OperationId field value
// and a boolean to check if the value has been set.
func (o *CancelOperationResponse) GetOperationIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.OperationId, true
}
// SetOperationId sets field value
func (o *CancelOperationResponse) SetOperationId(v string) {
o.OperationId = v
}
func (o CancelOperationResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o CancelOperationResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["success"] = o.Success
toSerialize["message"] = o.Message
toSerialize["operation_id"] = o.OperationId
return toSerialize, nil
}
func (o *CancelOperationResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"success",
"message",
"operation_id",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varCancelOperationResponse := _CancelOperationResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varCancelOperationResponse)
if err != nil {
return err
}
*o = CancelOperationResponse(varCancelOperationResponse)
return err
}
type NullableCancelOperationResponse struct {
value *CancelOperationResponse
isSet bool
}
func (v NullableCancelOperationResponse) Get() *CancelOperationResponse {
return v.value
}
func (v *NullableCancelOperationResponse) Set(val *CancelOperationResponse) {
v.value = val
v.isSet = true
}
func (v NullableCancelOperationResponse) IsSet() bool {
return v.isSet
}
func (v *NullableCancelOperationResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableCancelOperationResponse(val *CancelOperationResponse) *NullableCancelOperationResponse {
return &NullableCancelOperationResponse{value: val, isSet: true}
}
func (v NullableCancelOperationResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableCancelOperationResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,324 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the ChildOperationStatus type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &ChildOperationStatus{}
// ChildOperationStatus Status of a child operation (for batch operations).
type ChildOperationStatus struct {
OperationId string `json:"operation_id"`
Status string `json:"status"`
SubBatchIndex NullableInt32 `json:"sub_batch_index,omitempty"`
ItemsCount NullableInt32 `json:"items_count,omitempty"`
ErrorMessage NullableString `json:"error_message,omitempty"`
}
type _ChildOperationStatus ChildOperationStatus
// NewChildOperationStatus instantiates a new ChildOperationStatus object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewChildOperationStatus(operationId string, status string) *ChildOperationStatus {
this := ChildOperationStatus{}
this.OperationId = operationId
this.Status = status
return &this
}
// NewChildOperationStatusWithDefaults instantiates a new ChildOperationStatus object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewChildOperationStatusWithDefaults() *ChildOperationStatus {
this := ChildOperationStatus{}
return &this
}
// GetOperationId returns the OperationId field value
func (o *ChildOperationStatus) GetOperationId() string {
if o == nil {
var ret string
return ret
}
return o.OperationId
}
// GetOperationIdOk returns a tuple with the OperationId field value
// and a boolean to check if the value has been set.
func (o *ChildOperationStatus) GetOperationIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.OperationId, true
}
// SetOperationId sets field value
func (o *ChildOperationStatus) SetOperationId(v string) {
o.OperationId = v
}
// GetStatus returns the Status field value
func (o *ChildOperationStatus) GetStatus() string {
if o == nil {
var ret string
return ret
}
return o.Status
}
// GetStatusOk returns a tuple with the Status field value
// and a boolean to check if the value has been set.
func (o *ChildOperationStatus) GetStatusOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Status, true
}
// SetStatus sets field value
func (o *ChildOperationStatus) SetStatus(v string) {
o.Status = v
}
// GetSubBatchIndex returns the SubBatchIndex field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *ChildOperationStatus) GetSubBatchIndex() int32 {
if o == nil || IsNil(o.SubBatchIndex.Get()) {
var ret int32
return ret
}
return *o.SubBatchIndex.Get()
}
// GetSubBatchIndexOk returns a tuple with the SubBatchIndex field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *ChildOperationStatus) GetSubBatchIndexOk() (*int32, bool) {
if o == nil {
return nil, false
}
return o.SubBatchIndex.Get(), o.SubBatchIndex.IsSet()
}
// HasSubBatchIndex returns a boolean if a field has been set.
func (o *ChildOperationStatus) HasSubBatchIndex() bool {
if o != nil && o.SubBatchIndex.IsSet() {
return true
}
return false
}
// SetSubBatchIndex gets a reference to the given NullableInt32 and assigns it to the SubBatchIndex field.
func (o *ChildOperationStatus) SetSubBatchIndex(v int32) {
o.SubBatchIndex.Set(&v)
}
// SetSubBatchIndexNil sets the value for SubBatchIndex to be an explicit nil
func (o *ChildOperationStatus) SetSubBatchIndexNil() {
o.SubBatchIndex.Set(nil)
}
// UnsetSubBatchIndex ensures that no value is present for SubBatchIndex, not even an explicit nil
func (o *ChildOperationStatus) UnsetSubBatchIndex() {
o.SubBatchIndex.Unset()
}
// GetItemsCount returns the ItemsCount field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *ChildOperationStatus) GetItemsCount() int32 {
if o == nil || IsNil(o.ItemsCount.Get()) {
var ret int32
return ret
}
return *o.ItemsCount.Get()
}
// GetItemsCountOk returns a tuple with the ItemsCount field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *ChildOperationStatus) GetItemsCountOk() (*int32, bool) {
if o == nil {
return nil, false
}
return o.ItemsCount.Get(), o.ItemsCount.IsSet()
}
// HasItemsCount returns a boolean if a field has been set.
func (o *ChildOperationStatus) HasItemsCount() bool {
if o != nil && o.ItemsCount.IsSet() {
return true
}
return false
}
// SetItemsCount gets a reference to the given NullableInt32 and assigns it to the ItemsCount field.
func (o *ChildOperationStatus) SetItemsCount(v int32) {
o.ItemsCount.Set(&v)
}
// SetItemsCountNil sets the value for ItemsCount to be an explicit nil
func (o *ChildOperationStatus) SetItemsCountNil() {
o.ItemsCount.Set(nil)
}
// UnsetItemsCount ensures that no value is present for ItemsCount, not even an explicit nil
func (o *ChildOperationStatus) UnsetItemsCount() {
o.ItemsCount.Unset()
}
// GetErrorMessage returns the ErrorMessage field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *ChildOperationStatus) GetErrorMessage() string {
if o == nil || IsNil(o.ErrorMessage.Get()) {
var ret string
return ret
}
return *o.ErrorMessage.Get()
}
// GetErrorMessageOk returns a tuple with the ErrorMessage field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *ChildOperationStatus) GetErrorMessageOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.ErrorMessage.Get(), o.ErrorMessage.IsSet()
}
// HasErrorMessage returns a boolean if a field has been set.
func (o *ChildOperationStatus) HasErrorMessage() bool {
if o != nil && o.ErrorMessage.IsSet() {
return true
}
return false
}
// SetErrorMessage gets a reference to the given NullableString and assigns it to the ErrorMessage field.
func (o *ChildOperationStatus) SetErrorMessage(v string) {
o.ErrorMessage.Set(&v)
}
// SetErrorMessageNil sets the value for ErrorMessage to be an explicit nil
func (o *ChildOperationStatus) SetErrorMessageNil() {
o.ErrorMessage.Set(nil)
}
// UnsetErrorMessage ensures that no value is present for ErrorMessage, not even an explicit nil
func (o *ChildOperationStatus) UnsetErrorMessage() {
o.ErrorMessage.Unset()
}
func (o ChildOperationStatus) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o ChildOperationStatus) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["operation_id"] = o.OperationId
toSerialize["status"] = o.Status
if o.SubBatchIndex.IsSet() {
toSerialize["sub_batch_index"] = o.SubBatchIndex.Get()
}
if o.ItemsCount.IsSet() {
toSerialize["items_count"] = o.ItemsCount.Get()
}
if o.ErrorMessage.IsSet() {
toSerialize["error_message"] = o.ErrorMessage.Get()
}
return toSerialize, nil
}
func (o *ChildOperationStatus) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"operation_id",
"status",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varChildOperationStatus := _ChildOperationStatus{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varChildOperationStatus)
if err != nil {
return err
}
*o = ChildOperationStatus(varChildOperationStatus)
return err
}
type NullableChildOperationStatus struct {
value *ChildOperationStatus
isSet bool
}
func (v NullableChildOperationStatus) Get() *ChildOperationStatus {
return v.value
}
func (v *NullableChildOperationStatus) Set(val *ChildOperationStatus) {
v.value = val
v.isSet = true
}
func (v NullableChildOperationStatus) IsSet() bool {
return v.isSet
}
func (v *NullableChildOperationStatus) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableChildOperationStatus(val *ChildOperationStatus) *NullableChildOperationStatus {
return &NullableChildOperationStatus{value: val, isSet: true}
}
func (v NullableChildOperationStatus) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableChildOperationStatus) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
-255
View File
@@ -1,255 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the ChunkData type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &ChunkData{}
// ChunkData Chunk data for a single chunk.
type ChunkData struct {
Id string `json:"id"`
Text string `json:"text"`
ChunkIndex int32 `json:"chunk_index"`
// Whether the chunk text was truncated due to token limits
Truncated *bool `json:"truncated,omitempty"`
}
type _ChunkData ChunkData
// NewChunkData instantiates a new ChunkData object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewChunkData(id string, text string, chunkIndex int32) *ChunkData {
this := ChunkData{}
this.Id = id
this.Text = text
this.ChunkIndex = chunkIndex
var truncated bool = false
this.Truncated = &truncated
return &this
}
// NewChunkDataWithDefaults instantiates a new ChunkData object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewChunkDataWithDefaults() *ChunkData {
this := ChunkData{}
var truncated bool = false
this.Truncated = &truncated
return &this
}
// GetId returns the Id field value
func (o *ChunkData) GetId() string {
if o == nil {
var ret string
return ret
}
return o.Id
}
// GetIdOk returns a tuple with the Id field value
// and a boolean to check if the value has been set.
func (o *ChunkData) GetIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Id, true
}
// SetId sets field value
func (o *ChunkData) SetId(v string) {
o.Id = v
}
// GetText returns the Text field value
func (o *ChunkData) GetText() string {
if o == nil {
var ret string
return ret
}
return o.Text
}
// GetTextOk returns a tuple with the Text field value
// and a boolean to check if the value has been set.
func (o *ChunkData) GetTextOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Text, true
}
// SetText sets field value
func (o *ChunkData) SetText(v string) {
o.Text = v
}
// GetChunkIndex returns the ChunkIndex field value
func (o *ChunkData) GetChunkIndex() int32 {
if o == nil {
var ret int32
return ret
}
return o.ChunkIndex
}
// GetChunkIndexOk returns a tuple with the ChunkIndex field value
// and a boolean to check if the value has been set.
func (o *ChunkData) GetChunkIndexOk() (*int32, bool) {
if o == nil {
return nil, false
}
return &o.ChunkIndex, true
}
// SetChunkIndex sets field value
func (o *ChunkData) SetChunkIndex(v int32) {
o.ChunkIndex = v
}
// GetTruncated returns the Truncated field value if set, zero value otherwise.
func (o *ChunkData) GetTruncated() bool {
if o == nil || IsNil(o.Truncated) {
var ret bool
return ret
}
return *o.Truncated
}
// GetTruncatedOk returns a tuple with the Truncated field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *ChunkData) GetTruncatedOk() (*bool, bool) {
if o == nil || IsNil(o.Truncated) {
return nil, false
}
return o.Truncated, true
}
// HasTruncated returns a boolean if a field has been set.
func (o *ChunkData) HasTruncated() bool {
if o != nil && !IsNil(o.Truncated) {
return true
}
return false
}
// SetTruncated gets a reference to the given bool and assigns it to the Truncated field.
func (o *ChunkData) SetTruncated(v bool) {
o.Truncated = &v
}
func (o ChunkData) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o ChunkData) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["id"] = o.Id
toSerialize["text"] = o.Text
toSerialize["chunk_index"] = o.ChunkIndex
if !IsNil(o.Truncated) {
toSerialize["truncated"] = o.Truncated
}
return toSerialize, nil
}
func (o *ChunkData) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"id",
"text",
"chunk_index",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varChunkData := _ChunkData{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varChunkData)
if err != nil {
return err
}
*o = ChunkData(varChunkData)
return err
}
type NullableChunkData struct {
value *ChunkData
isSet bool
}
func (v NullableChunkData) Get() *ChunkData {
return v.value
}
func (v *NullableChunkData) Set(val *ChunkData) {
v.value = val
v.isSet = true
}
func (v NullableChunkData) IsSet() bool {
return v.isSet
}
func (v *NullableChunkData) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableChunkData(val *ChunkData) *NullableChunkData {
return &NullableChunkData{value: val, isSet: true}
}
func (v NullableChunkData) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableChunkData) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,131 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
)
// checks if the ChunkIncludeOptions type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &ChunkIncludeOptions{}
// ChunkIncludeOptions Options for including chunks in recall results.
type ChunkIncludeOptions struct {
// Maximum tokens for chunks (chunks may be truncated)
MaxTokens *int32 `json:"max_tokens,omitempty"`
}
// NewChunkIncludeOptions instantiates a new ChunkIncludeOptions object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewChunkIncludeOptions() *ChunkIncludeOptions {
this := ChunkIncludeOptions{}
var maxTokens int32 = 8192
this.MaxTokens = &maxTokens
return &this
}
// NewChunkIncludeOptionsWithDefaults instantiates a new ChunkIncludeOptions object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewChunkIncludeOptionsWithDefaults() *ChunkIncludeOptions {
this := ChunkIncludeOptions{}
var maxTokens int32 = 8192
this.MaxTokens = &maxTokens
return &this
}
// GetMaxTokens returns the MaxTokens field value if set, zero value otherwise.
func (o *ChunkIncludeOptions) GetMaxTokens() int32 {
if o == nil || IsNil(o.MaxTokens) {
var ret int32
return ret
}
return *o.MaxTokens
}
// GetMaxTokensOk returns a tuple with the MaxTokens field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *ChunkIncludeOptions) GetMaxTokensOk() (*int32, bool) {
if o == nil || IsNil(o.MaxTokens) {
return nil, false
}
return o.MaxTokens, true
}
// HasMaxTokens returns a boolean if a field has been set.
func (o *ChunkIncludeOptions) HasMaxTokens() bool {
if o != nil && !IsNil(o.MaxTokens) {
return true
}
return false
}
// SetMaxTokens gets a reference to the given int32 and assigns it to the MaxTokens field.
func (o *ChunkIncludeOptions) SetMaxTokens(v int32) {
o.MaxTokens = &v
}
func (o ChunkIncludeOptions) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o ChunkIncludeOptions) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
if !IsNil(o.MaxTokens) {
toSerialize["max_tokens"] = o.MaxTokens
}
return toSerialize, nil
}
type NullableChunkIncludeOptions struct {
value *ChunkIncludeOptions
isSet bool
}
func (v NullableChunkIncludeOptions) Get() *ChunkIncludeOptions {
return v.value
}
func (v *NullableChunkIncludeOptions) Set(val *ChunkIncludeOptions) {
v.value = val
v.isSet = true
}
func (v NullableChunkIncludeOptions) IsSet() bool {
return v.isSet
}
func (v *NullableChunkIncludeOptions) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableChunkIncludeOptions(val *ChunkIncludeOptions) *NullableChunkIncludeOptions {
return &NullableChunkIncludeOptions{value: val, isSet: true}
}
func (v NullableChunkIncludeOptions) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableChunkIncludeOptions) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,298 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the ChunkResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &ChunkResponse{}
// ChunkResponse Response model for get chunk endpoint.
type ChunkResponse struct {
ChunkId string `json:"chunk_id"`
DocumentId string `json:"document_id"`
BankId string `json:"bank_id"`
ChunkIndex int32 `json:"chunk_index"`
ChunkText string `json:"chunk_text"`
CreatedAt string `json:"created_at"`
}
type _ChunkResponse ChunkResponse
// NewChunkResponse instantiates a new ChunkResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewChunkResponse(chunkId string, documentId string, bankId string, chunkIndex int32, chunkText string, createdAt string) *ChunkResponse {
this := ChunkResponse{}
this.ChunkId = chunkId
this.DocumentId = documentId
this.BankId = bankId
this.ChunkIndex = chunkIndex
this.ChunkText = chunkText
this.CreatedAt = createdAt
return &this
}
// NewChunkResponseWithDefaults instantiates a new ChunkResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewChunkResponseWithDefaults() *ChunkResponse {
this := ChunkResponse{}
return &this
}
// GetChunkId returns the ChunkId field value
func (o *ChunkResponse) GetChunkId() string {
if o == nil {
var ret string
return ret
}
return o.ChunkId
}
// GetChunkIdOk returns a tuple with the ChunkId field value
// and a boolean to check if the value has been set.
func (o *ChunkResponse) GetChunkIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.ChunkId, true
}
// SetChunkId sets field value
func (o *ChunkResponse) SetChunkId(v string) {
o.ChunkId = v
}
// GetDocumentId returns the DocumentId field value
func (o *ChunkResponse) GetDocumentId() string {
if o == nil {
var ret string
return ret
}
return o.DocumentId
}
// GetDocumentIdOk returns a tuple with the DocumentId field value
// and a boolean to check if the value has been set.
func (o *ChunkResponse) GetDocumentIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.DocumentId, true
}
// SetDocumentId sets field value
func (o *ChunkResponse) SetDocumentId(v string) {
o.DocumentId = v
}
// GetBankId returns the BankId field value
func (o *ChunkResponse) GetBankId() string {
if o == nil {
var ret string
return ret
}
return o.BankId
}
// GetBankIdOk returns a tuple with the BankId field value
// and a boolean to check if the value has been set.
func (o *ChunkResponse) GetBankIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.BankId, true
}
// SetBankId sets field value
func (o *ChunkResponse) SetBankId(v string) {
o.BankId = v
}
// GetChunkIndex returns the ChunkIndex field value
func (o *ChunkResponse) GetChunkIndex() int32 {
if o == nil {
var ret int32
return ret
}
return o.ChunkIndex
}
// GetChunkIndexOk returns a tuple with the ChunkIndex field value
// and a boolean to check if the value has been set.
func (o *ChunkResponse) GetChunkIndexOk() (*int32, bool) {
if o == nil {
return nil, false
}
return &o.ChunkIndex, true
}
// SetChunkIndex sets field value
func (o *ChunkResponse) SetChunkIndex(v int32) {
o.ChunkIndex = v
}
// GetChunkText returns the ChunkText field value
func (o *ChunkResponse) GetChunkText() string {
if o == nil {
var ret string
return ret
}
return o.ChunkText
}
// GetChunkTextOk returns a tuple with the ChunkText field value
// and a boolean to check if the value has been set.
func (o *ChunkResponse) GetChunkTextOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.ChunkText, true
}
// SetChunkText sets field value
func (o *ChunkResponse) SetChunkText(v string) {
o.ChunkText = v
}
// GetCreatedAt returns the CreatedAt field value
func (o *ChunkResponse) GetCreatedAt() string {
if o == nil {
var ret string
return ret
}
return o.CreatedAt
}
// GetCreatedAtOk returns a tuple with the CreatedAt field value
// and a boolean to check if the value has been set.
func (o *ChunkResponse) GetCreatedAtOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.CreatedAt, true
}
// SetCreatedAt sets field value
func (o *ChunkResponse) SetCreatedAt(v string) {
o.CreatedAt = v
}
func (o ChunkResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o ChunkResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["chunk_id"] = o.ChunkId
toSerialize["document_id"] = o.DocumentId
toSerialize["bank_id"] = o.BankId
toSerialize["chunk_index"] = o.ChunkIndex
toSerialize["chunk_text"] = o.ChunkText
toSerialize["created_at"] = o.CreatedAt
return toSerialize, nil
}
func (o *ChunkResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"chunk_id",
"document_id",
"bank_id",
"chunk_index",
"chunk_text",
"created_at",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varChunkResponse := _ChunkResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varChunkResponse)
if err != nil {
return err
}
*o = ChunkResponse(varChunkResponse)
return err
}
type NullableChunkResponse struct {
value *ChunkResponse
isSet bool
}
func (v NullableChunkResponse) Get() *ChunkResponse {
return v.value
}
func (v *NullableChunkResponse) Set(val *ChunkResponse) {
v.value = val
v.isSet = true
}
func (v NullableChunkResponse) IsSet() bool {
return v.isSet
}
func (v *NullableChunkResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableChunkResponse(val *ChunkResponse) *NullableChunkResponse {
return &NullableChunkResponse{value: val, isSet: true}
}
func (v NullableChunkResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableChunkResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,200 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the ConsolidationResponse type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &ConsolidationResponse{}
// ConsolidationResponse Response model for consolidation trigger endpoint.
type ConsolidationResponse struct {
// ID of the async consolidation operation
OperationId string `json:"operation_id"`
// True if an existing pending task was reused
Deduplicated *bool `json:"deduplicated,omitempty"`
}
type _ConsolidationResponse ConsolidationResponse
// NewConsolidationResponse instantiates a new ConsolidationResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewConsolidationResponse(operationId string) *ConsolidationResponse {
this := ConsolidationResponse{}
this.OperationId = operationId
var deduplicated bool = false
this.Deduplicated = &deduplicated
return &this
}
// NewConsolidationResponseWithDefaults instantiates a new ConsolidationResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewConsolidationResponseWithDefaults() *ConsolidationResponse {
this := ConsolidationResponse{}
var deduplicated bool = false
this.Deduplicated = &deduplicated
return &this
}
// GetOperationId returns the OperationId field value
func (o *ConsolidationResponse) GetOperationId() string {
if o == nil {
var ret string
return ret
}
return o.OperationId
}
// GetOperationIdOk returns a tuple with the OperationId field value
// and a boolean to check if the value has been set.
func (o *ConsolidationResponse) GetOperationIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.OperationId, true
}
// SetOperationId sets field value
func (o *ConsolidationResponse) SetOperationId(v string) {
o.OperationId = v
}
// GetDeduplicated returns the Deduplicated field value if set, zero value otherwise.
func (o *ConsolidationResponse) GetDeduplicated() bool {
if o == nil || IsNil(o.Deduplicated) {
var ret bool
return ret
}
return *o.Deduplicated
}
// GetDeduplicatedOk returns a tuple with the Deduplicated field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *ConsolidationResponse) GetDeduplicatedOk() (*bool, bool) {
if o == nil || IsNil(o.Deduplicated) {
return nil, false
}
return o.Deduplicated, true
}
// HasDeduplicated returns a boolean if a field has been set.
func (o *ConsolidationResponse) HasDeduplicated() bool {
if o != nil && !IsNil(o.Deduplicated) {
return true
}
return false
}
// SetDeduplicated gets a reference to the given bool and assigns it to the Deduplicated field.
func (o *ConsolidationResponse) SetDeduplicated(v bool) {
o.Deduplicated = &v
}
func (o ConsolidationResponse) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o ConsolidationResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["operation_id"] = o.OperationId
if !IsNil(o.Deduplicated) {
toSerialize["deduplicated"] = o.Deduplicated
}
return toSerialize, nil
}
func (o *ConsolidationResponse) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"operation_id",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varConsolidationResponse := _ConsolidationResponse{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varConsolidationResponse)
if err != nil {
return err
}
*o = ConsolidationResponse(varConsolidationResponse)
return err
}
type NullableConsolidationResponse struct {
value *ConsolidationResponse
isSet bool
}
func (v NullableConsolidationResponse) Get() *ConsolidationResponse {
return v.value
}
func (v *NullableConsolidationResponse) Set(val *ConsolidationResponse) {
v.value = val
v.isSet = true
}
func (v NullableConsolidationResponse) IsSet() bool {
return v.isSet
}
func (v *NullableConsolidationResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableConsolidationResponse(val *ConsolidationResponse) *NullableConsolidationResponse {
return &NullableConsolidationResponse{value: val, isSet: true}
}
func (v NullableConsolidationResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableConsolidationResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
@@ -1,274 +0,0 @@
/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.11
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
)
// checks if the CreateBankRequest type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &CreateBankRequest{}
// CreateBankRequest Request model for creating/updating a bank.
type CreateBankRequest struct {
Name NullableString `json:"name,omitempty"`
Disposition NullableDispositionTraits `json:"disposition,omitempty"`
Mission NullableString `json:"mission,omitempty"`
Background NullableString `json:"background,omitempty"`
}
// NewCreateBankRequest instantiates a new CreateBankRequest object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewCreateBankRequest() *CreateBankRequest {
this := CreateBankRequest{}
return &this
}
// NewCreateBankRequestWithDefaults instantiates a new CreateBankRequest object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewCreateBankRequestWithDefaults() *CreateBankRequest {
this := CreateBankRequest{}
return &this
}
// GetName returns the Name field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *CreateBankRequest) GetName() string {
if o == nil || IsNil(o.Name.Get()) {
var ret string
return ret
}
return *o.Name.Get()
}
// GetNameOk returns a tuple with the Name field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *CreateBankRequest) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Name.Get(), o.Name.IsSet()
}
// HasName returns a boolean if a field has been set.
func (o *CreateBankRequest) HasName() bool {
if o != nil && o.Name.IsSet() {
return true
}
return false
}
// SetName gets a reference to the given NullableString and assigns it to the Name field.
func (o *CreateBankRequest) SetName(v string) {
o.Name.Set(&v)
}
// SetNameNil sets the value for Name to be an explicit nil
func (o *CreateBankRequest) SetNameNil() {
o.Name.Set(nil)
}
// UnsetName ensures that no value is present for Name, not even an explicit nil
func (o *CreateBankRequest) UnsetName() {
o.Name.Unset()
}
// GetDisposition returns the Disposition field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *CreateBankRequest) GetDisposition() DispositionTraits {
if o == nil || IsNil(o.Disposition.Get()) {
var ret DispositionTraits
return ret
}
return *o.Disposition.Get()
}
// GetDispositionOk returns a tuple with the Disposition field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *CreateBankRequest) GetDispositionOk() (*DispositionTraits, bool) {
if o == nil {
return nil, false
}
return o.Disposition.Get(), o.Disposition.IsSet()
}
// HasDisposition returns a boolean if a field has been set.
func (o *CreateBankRequest) HasDisposition() bool {
if o != nil && o.Disposition.IsSet() {
return true
}
return false
}
// SetDisposition gets a reference to the given NullableDispositionTraits and assigns it to the Disposition field.
func (o *CreateBankRequest) SetDisposition(v DispositionTraits) {
o.Disposition.Set(&v)
}
// SetDispositionNil sets the value for Disposition to be an explicit nil
func (o *CreateBankRequest) SetDispositionNil() {
o.Disposition.Set(nil)
}
// UnsetDisposition ensures that no value is present for Disposition, not even an explicit nil
func (o *CreateBankRequest) UnsetDisposition() {
o.Disposition.Unset()
}
// GetMission returns the Mission field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *CreateBankRequest) GetMission() string {
if o == nil || IsNil(o.Mission.Get()) {
var ret string
return ret
}
return *o.Mission.Get()
}
// GetMissionOk returns a tuple with the Mission field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *CreateBankRequest) GetMissionOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Mission.Get(), o.Mission.IsSet()
}
// HasMission returns a boolean if a field has been set.
func (o *CreateBankRequest) HasMission() bool {
if o != nil && o.Mission.IsSet() {
return true
}
return false
}
// SetMission gets a reference to the given NullableString and assigns it to the Mission field.
func (o *CreateBankRequest) SetMission(v string) {
o.Mission.Set(&v)
}
// SetMissionNil sets the value for Mission to be an explicit nil
func (o *CreateBankRequest) SetMissionNil() {
o.Mission.Set(nil)
}
// UnsetMission ensures that no value is present for Mission, not even an explicit nil
func (o *CreateBankRequest) UnsetMission() {
o.Mission.Unset()
}
// GetBackground returns the Background field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *CreateBankRequest) GetBackground() string {
if o == nil || IsNil(o.Background.Get()) {
var ret string
return ret
}
return *o.Background.Get()
}
// GetBackgroundOk returns a tuple with the Background field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *CreateBankRequest) GetBackgroundOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Background.Get(), o.Background.IsSet()
}
// HasBackground returns a boolean if a field has been set.
func (o *CreateBankRequest) HasBackground() bool {
if o != nil && o.Background.IsSet() {
return true
}
return false
}
// SetBackground gets a reference to the given NullableString and assigns it to the Background field.
func (o *CreateBankRequest) SetBackground(v string) {
o.Background.Set(&v)
}
// SetBackgroundNil sets the value for Background to be an explicit nil
func (o *CreateBankRequest) SetBackgroundNil() {
o.Background.Set(nil)
}
// UnsetBackground ensures that no value is present for Background, not even an explicit nil
func (o *CreateBankRequest) UnsetBackground() {
o.Background.Unset()
}
func (o CreateBankRequest) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o CreateBankRequest) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
if o.Name.IsSet() {
toSerialize["name"] = o.Name.Get()
}
if o.Disposition.IsSet() {
toSerialize["disposition"] = o.Disposition.Get()
}
if o.Mission.IsSet() {
toSerialize["mission"] = o.Mission.Get()
}
if o.Background.IsSet() {
toSerialize["background"] = o.Background.Get()
}
return toSerialize, nil
}
type NullableCreateBankRequest struct {
value *CreateBankRequest
isSet bool
}
func (v NullableCreateBankRequest) Get() *CreateBankRequest {
return v.value
}
func (v *NullableCreateBankRequest) Set(val *CreateBankRequest) {
v.value = val
v.isSet = true
}
func (v NullableCreateBankRequest) IsSet() bool {
return v.isSet
}
func (v *NullableCreateBankRequest) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableCreateBankRequest(val *CreateBankRequest) *NullableCreateBankRequest {
return &NullableCreateBankRequest{value: val, isSet: true}
}
func (v NullableCreateBankRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableCreateBankRequest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

Some files were not shown because too many files have changed in this diff Show More