repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
onyx | backend/onyx/db/security_settings.py | .py | """Persistence for the singleton ``security_settings`` row.
One row per tenant schema (boolean PK pinned to ``true``). Every column is
an *override*: ``NULL`` == "fall back to env default".
"""
from sqlalchemy import select
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.orm import Session
from ony... | 40 | 1,557 |
onyx | backend/onyx/db/memory.py | .py | from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field
from sqlalchemy import select
from sqlalchemy.orm import Session
from onyx.auth.login_claims_capture import get_idp_profile
from onyx.db.engine.sql_engine import get_session_with_current_tenant_if_none
from onyx.db.models import Memory, User
MAX... | 160 | 5,587 |
onyx | backend/onyx/db/connector_alerts.py | .py | from typing import Any
from sqlalchemy.orm import Session
from onyx.configs.constants import NotificationType
from onyx.db.enums import NotificationSeverity
from onyx.db.notification import (
batch_create_notifications,
delete_notifications_by_additional_data,
)
from onyx.db.users import get_active_admin_user... | 67 | 2,167 |
onyx | backend/onyx/db/kg_config.py | .py | from onyx.configs.constants import KV_KG_CONFIG_KEY
from onyx.key_value_store.factory import get_kv_store
from onyx.key_value_store.interface import KvKeyNotFoundError
from onyx.kg.models import KGConfigSettings
from onyx.server.kg.models import EnableKGConfigRequest
from onyx.utils.logger import setup_logger
logger =... | 67 | 2,562 |
onyx | backend/onyx/db/file_content.py | .py | from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.orm import Session
from onyx.db.file_record import FileRecordNotFoundError
from onyx.db.models import FileContent
def get_file_content_by_file_id(
file_id: str,
db_session: Session,
) -> FileContent:
record = db_session.query(FileContent).... | 79 | 2,349 |
onyx | backend/onyx/db/engine/async_sql_engine.py | .py | import asyncio
import threading
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from typing import Any, AsyncContextManager
from fastapi import HTTPException
from sqlalchemy import event, pool
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
from ... | 211 | 7,543 |
onyx | backend/onyx/db/engine/tenant_utils.py | .py | import re
from itertools import chain
from sqlalchemy import text
from sqlalchemy.engine import Engine
from onyx.db.engine.shard_registry import (
get_default_shard_name,
get_engine_for_shard,
get_shard_specs,
)
from shared_configs.configs import (
MULTI_TENANT,
POSTGRES_DEFAULT_SCHEMA,
TENANT... | 183 | 7,213 |
onyx | backend/onyx/db/engine/shard_routing.py | .py | """Resolve a tenant to the physical database ("shard") holding its schema.
This sits on the request hot path, so it must not issue a catalog query per session.
Resolution order:
1. ``ONYX_DB_SHARD_OVERRIDES`` β static operator escape hatch, no I/O.
2. In-process TTL cache, invalidated across processes by the Redis ve... | 263 | 9,358 |
onyx | backend/onyx/db/engine/time_utils.py | .py | from datetime import datetime
from sqlalchemy import text
from sqlalchemy.orm import Session
def get_db_current_time(db_session: Session) -> datetime:
result = db_session.execute(text("SELECT NOW()")).scalar()
if result is None:
raise ValueError("Database did not return a time")
return result
| 12 | 317 |
onyx | backend/onyx/db/engine/shard_version.py | .py | """Cross-process invalidation for the tenant -> shard routing cache.
Every process caches tenant -> shard resolutions in memory (see ``shard_routing``).
When the migrator moves a tenant it flips the ``tenant_shard`` row, but each process
keeps serving its cached answer until that entry expires. Routing a request with ... | 185 | 7,295 |
onyx | backend/onyx/db/engine/iam_auth.py | .py | import functools
import os
import ssl
from typing import Any
import boto3
from onyx.configs.app_configs import (
POSTGRES_HOST,
POSTGRES_PORT,
POSTGRES_USER,
USE_IAM_AUTH,
)
from onyx.configs.constants import SSL_CERT_FILE
def get_iam_auth_token(
host: str, port: str, user: str, region: str = "u... | 98 | 2,958 |
onyx | backend/onyx/db/engine/sql_engine.py | .py | import os
import re
import threading
import time
from collections.abc import Generator
from contextlib import contextmanager
from dataclasses import dataclass
from typing import Any
from fastapi import HTTPException
from sqlalchemy import event, pool
from sqlalchemy.engine import Engine, create_engine
from sqlalchemy.... | 595 | 21,511 |
onyx | backend/onyx/db/engine/connection_warmup.py | .py | from sqlalchemy import text
from onyx.db.engine.async_sql_engine import get_sqlalchemy_async_engine
from onyx.db.engine.sql_engine import get_sqlalchemy_engine
async def warm_up_connections(
sync_connections_to_warm_up: int = 20, async_connections_to_warm_up: int = 20
) -> None:
sync_postgres_engine = get_sq... | 28 | 921 |
onyx | backend/onyx/db/engine/pg_ssl.py | .py | """Single source of truth for PostgreSQL TLS configuration.
Two drivers, two mechanisms:
- psycopg2 (sync) speaks libpq directly, so it takes ``sslmode`` / ``sslrootcert``
as ``connect_args`` keys.
- asyncpg (async) does NOT accept libpq ``sslmode`` keys. Verifying against a
custom CA requires an ``ssl.SSLContext... | 105 | 3,936 |
onyx | backend/onyx/db/engine/shard_registry.py | .py | """Physical database ("shard") registry for tenant routing.
Onyx addresses a tenant by *schema* via ``schema_translate_map``. This module adds
the orthogonal axis: which *database* that schema lives in.
Design notes:
- The default shard's engine is owned by :class:`onyx.db.engine.sql_engine.SqlEngine`,
not by this... | 404 | 14,127 |
onyx | backend/onyx/db/seeding/chat_history_seeding.py | .py | import random
from datetime import datetime, timedelta, timezone
from logging import getLogger
from uuid import UUID
from onyx.configs.constants import MessageType
from onyx.db.chat import (
create_chat_session,
create_new_chat_message,
get_or_create_root_message,
)
from onyx.db.engine.sql_engine import ge... | 93 | 3,275 |
onyx | backend/onyx/db/_deprecated/pg_file_store.py | .py | """Kept around since it's used in the migration to move to S3/MinIO"""
import tempfile
from io import BytesIO
from typing import IO
from psycopg2.extensions import connection
from sqlalchemy import text # NEW: for SQL large-object helpers
from sqlalchemy.orm import Session
from onyx.file_store.constants import MAX_... | 142 | 4,627 |
onyx | backend/onyx/evals/provider.py | .py | from onyx.evals.models import EvalProvider
from onyx.evals.providers.braintrust import BraintrustEvalProvider
from onyx.evals.providers.local import LocalEvalProvider
def get_provider(local_only: bool = False) -> EvalProvider:
"""
Get the appropriate eval provider.
Args:
local_only: If True, use ... | 20 | 588 |
onyx | backend/onyx/evals/models.py | .py | from abc import ABC, abstractmethod
from collections.abc import Callable
from typing import Any
from pydantic import BaseModel, Field
from sqlalchemy.orm import Session
from onyx.db.tools import get_builtin_tool
from onyx.llm.override_models import LLMOverride
from onyx.server.query_and_chat.streaming_models import C... | 126 | 4,356 |
onyx | backend/onyx/evals/eval.py | .py | import time
from collections.abc import Callable, Generator
from contextlib import contextmanager
from typing import Any
from sqlalchemy import Engine, event
from sqlalchemy.orm import Session, sessionmaker
from sqlalchemy.orm.session import SessionTransaction
from onyx.chat.chat_state import ChatStateContainer
from ... | 469 | 18,633 |
onyx | backend/onyx/evals/eval_cli.py | .py | #!/usr/bin/env python3
"""
CLI for running evaluations with local configurations.
"""
import argparse
import json
import logging
import os
from typing import Any
import braintrust
import requests
from onyx.configs.app_configs import (
POSTGRES_API_SERVER_POOL_OVERFLOW,
POSTGRES_API_SERVER_POOL_SIZE,
)
from o... | 299 | 9,256 |
onyx | backend/onyx/evals/one_off/create_braintrust_dataset.py | .py | #!/usr/bin/env python3
"""
Script to create a Braintrust dataset from the DR Master Question & Metric Sheet CSV.
This script:
1. Parses the CSV file
2. Filters records where "Should we use it" is TRUE and "web-only" is in categories
3. Creates a Braintrust dataset with Question as input and research_type metadata
Usa... | 236 | 8,621 |
onyx | backend/onyx/evals/providers/braintrust.py | .py | from collections.abc import Callable
from typing import Any, Union
from braintrust import Eval, EvalCase, Score, init_dataset
from onyx.configs.app_configs import BRAINTRUST_MAX_CONCURRENCY, BRAINTRUST_PROJECT
from onyx.evals.models import (
EvalationAck,
EvalConfigurationOptions,
EvalProvider,
EvalTo... | 161 | 5,970 |
onyx | backend/onyx/evals/providers/local.py | .py | """
Local eval provider that runs evaluations and outputs results to the CLI.
No external dependencies like Braintrust required.
"""
from collections.abc import Callable
from typing import Any
from onyx.evals.models import (
EvalationAck,
EvalConfigurationOptions,
EvalProvider,
EvalToolResult,
Mul... | 238 | 8,334 |
onyx | backend/onyx/cache/postgres_backend.py | .py | """PostgreSQL-backed ``CacheBackend`` for NO_VECTOR_DB deployments.
Uses the ``cache_store`` table for key-value storage, PostgreSQL advisory locks
for distributed locking, and a polling loop for the BLPOP pattern.
"""
import hashlib
import struct
import time
import uuid
from contextlib import AbstractContextManager
... | 326 | 11,640 |
onyx | backend/onyx/cache/locks.py | .py | import time
from collections.abc import Generator
from contextlib import contextmanager
from logging import Logger, LoggerAdapter
from onyx.cache.factory import get_shared_cache_backend
from onyx.cache.interface import CacheLockAcquisitionError
@contextmanager
def cache_shared_lock(
lock_name: str,
max_time_... | 57 | 2,338 |
onyx | backend/onyx/cache/factory.py | .py | from collections.abc import Callable
from onyx.cache.interface import CacheBackend, CacheBackendType
from onyx.configs.app_configs import CACHE_BACKEND
def _build_redis_backend(tenant_id: str) -> CacheBackend:
from onyx.cache.redis_backend import RedisCacheBackend
from onyx.redis.redis_pool import redis_pool... | 50 | 1,664 |
onyx | backend/onyx/cache/redis_backend.py | .py | import math
from redis.exceptions import LockNotOwnedError
from redis.lock import Lock as RedisLock
from onyx.cache.interface import CacheBackend, CacheLock, CacheLockLostError
from onyx.redis.tenant_redis_client import TenantRedisClient
class RedisCacheLock(CacheLock):
"""Wraps ``redis.lock.Lock`` behind the `... | 92 | 2,852 |
onyx | backend/onyx/cache/interface.py | .py | import abc
from enum import Enum
from redis.exceptions import RedisError
from sqlalchemy.exc import SQLAlchemyError
TTL_KEY_NOT_FOUND = -2
TTL_NO_EXPIRY = -1
CACHE_TRANSIENT_ERRORS: tuple[type[Exception], ...] = (RedisError, SQLAlchemyError)
"""
Exception types that represent transient cache connectivity / operation... | 134 | 4,027 |
onyx | backend/onyx/sandbox_proxy/server.py | .py | """mitmproxy entrypoint for the sandbox egress proxy."""
import asyncio
import os
import signal
import sys
import threading
import uuid
from collections.abc import Callable
from http.server import BaseHTTPRequestHandler, HTTPServer
from mitmproxy.options import Options
from mitmproxy.tools.dump import DumpMaster
fro... | 296 | 9,832 |
onyx | backend/onyx/sandbox_proxy/errors.py | .py | """Sandbox-facing 403 error codes and response builder.
Every 403 the proxy returns to the sandbox carries a stable `error` code plus a
human-readable `message`. The agent running in the sandbox reads the `message`
to understand what happened and what to do next; tooling and dashboards match on
the stable `error` code... | 123 | 5,762 |
onyx | backend/onyx/sandbox_proxy/ca_docker.py | .py | """Docker-compose implementation of the CA persistence layer.
A shared compose-named volume is the source of truth: the proxy mounts it
read-write so it can persist on cold start; every sandbox container mounts it
read-only so ``firewall-init.sh`` can install ``ca.crt`` into the trust store.
That mount also makes ``ca... | 137 | 5,772 |
onyx | backend/onyx/sandbox_proxy/approval_cache.py | .py | """Ephemeral cache signals for the approval rendezvous.
The Postgres `action_approval` row is the source of truth; everything
here is best-effort over `CacheBackend`. Two lists:
* `approval:announce:{session_id}` β proxy RPUSHes after committing the
row; the chat-stream merger BLPOPs to emit the card on the live SS... | 202 | 6,516 |
onyx | backend/onyx/sandbox_proxy/credential_injection.py | .py | """Host-claim dispatcher for sandbox-proxy credential injection.
`CredentialInjectionDispatcher` walks a registered list of `CredentialResolver`s
and asks each in turn whether it owns the request. The first one that claims
renders its auth headers; the dispatcher writes them onto `flow.request` so the
real secret neve... | 159 | 5,598 |
onyx | backend/onyx/sandbox_proxy/mcp_jsonrpc.py | .py | """Classify an MCP streamable-HTTP request into a gate verdict input.
Every tool invocation is a JSON-RPC ``tools/call`` carrying the exact tool
name, so the gate parses the body (precedent:
``external_apps/matching/graphql_parsing.py``) rather than guessing from the
URL. Protocol plumbing passes ungated; anything els... | 136 | 4,588 |
onyx | backend/onyx/sandbox_proxy/identity_k8s.py | .py | """Kubernetes implementation of `SandboxIPLookup`.
Background thread watches sandbox pods and maintains a `{pod_ip:
SandboxIdentity}` cache. On any error or EOF the watch loop reconnects with
exponential backoff capped at `_RECONNECT_MAX_SECONDS`; on 410 Gone we relist.
"""
import threading
from uuid import UUID
fro... | 259 | 9,099 |
onyx | backend/onyx/sandbox_proxy/logging_utils.py | .py | """Shared rendering helpers for sandbox proxy logs."""
from uuid import UUID
from mitmproxy import http
from onyx.db.enums import EndpointPolicy
from onyx.external_apps.matching.engine import AllMatchedActions
from onyx.sandbox_proxy.credential_injection import InjectionOutcome
from onyx.sandbox_proxy.identity impor... | 164 | 4,749 |
onyx | backend/onyx/sandbox_proxy/request_evaluator.py | .py | """Classify an intercepted HTTPS request into a gated action.
The gate addon treats both a `None` return and any matcher exception as
"not gated" β the real security boundary is the proxy's iptables egress
lockdown, not this heuristic.
"""
import json
import re
from collections import Counter
from collections.abc imp... | 306 | 11,717 |
onyx | backend/onyx/sandbox_proxy/identity.py | .py | """Source-IP -> sandbox identity + in-band session resolution.
`IdentityResolver` splits resolution in two so non-gated traffic (npm install,
apt update) can flow once the pod is identified, while only gated traffic needs
a resolvable session:
- `resolve_sandbox()` β pod IP -> sandbox + user + tenant; enforces "only ... | 151 | 4,681 |
onyx | backend/onyx/sandbox_proxy/ca_k8s.py | .py | """Kubernetes implementation of the CA persistence layer.
The Secret in the proxy's namespace is the source of truth. A
ConfigMap in the sandbox namespace mirrors only the public cert so
sandbox init containers can mount it (K8s does not allow
cross-namespace ConfigMap mounts).
"""
import base64
import binascii
impor... | 184 | 6,355 |
onyx | backend/onyx/sandbox_proxy/identity_docker.py | .py | """Docker-compose implementation of ``SandboxIPLookup``.
Background thread streams ``DockerClient.events()`` filtered to sandbox
containers and maintains a ``{container_ip: SandboxIdentity}`` cache. On any
error or EOF the loop reconnects with exponential backoff capped at
``_RECONNECT_MAX_SECONDS``.
Mirrors the K8s ... | 323 | 12,643 |
onyx | backend/onyx/sandbox_proxy/ca.py | .py | """CA bootstrap for the sandbox egress proxy."""
import datetime as dt
import os
from dataclasses import dataclass
from pathlib import Path
from typing import Protocol
from cryptography import x509
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import r... | 205 | 7,563 |
onyx | backend/onyx/sandbox_proxy/backend.py | .py | """Backend-aware constructors for the swappable proxy stores.
``server.py`` calls these instead of instantiating ``K8sSecretCAStore`` /
``K8sInformerLookup`` (or their docker analogues) directly so the proxy boots
correctly under either ``SANDBOX_BACKEND`` value.
Imports of the K8s and docker concrete classes are def... | 41 | 1,644 |
onyx | backend/onyx/sandbox_proxy/resolvers/external_app.py | .py | """External-app credential resolver.
Claims a request iff the matcher has attributed it to a connected `ExternalApp`
(`ctx.matched_actions is not None`) and renders the app's `auth_template` from the org +
per-user credentials via `resolve_injection_headers`. Per-header fail-open
behaviour for missing placeholders liv... | 83 | 3,385 |
onyx | backend/onyx/sandbox_proxy/resolvers/mcp_matching.py | .py | """Shared craft-MCP request attribution.
The credential resolver and the approval evaluator must agree, exactly, on which
craft-enabled `MCPServer` (if any) a sandbox request belongs to β otherwise a
request could be gated as one server but injected with another's credentials, or
gated by one layer and not the other. ... | 121 | 4,210 |
onyx | backend/onyx/sandbox_proxy/resolvers/mcp_server.py | .py | """Craft MCP-server credential resolver.
Claims sandbox egress to a craft-enabled `MCPServer`'s `server_url` and injects
the sandbox owner's credentials from the same `mcp_connection_config` rows chat
writes, so authenticating on either surface authenticates both. Attribution is
an exact scheme + host + port + path-pr... | 302 | 13,175 |
onyx | backend/onyx/sandbox_proxy/resolvers/onyx_pat.py | .py | """Onyx-API PAT credential resolver.
Claims requests bound for the Onyx API host (the host of ``ONYX_SERVER_URL``)
and sets both auth headers to the sandbox's real per-sandbox PAT, read
encrypted off ``Sandbox.encrypted_pat``. The tenant is embedded in the PAT
itself, so no separate tenant header is injected.
"""
fro... | 83 | 3,000 |
onyx | backend/onyx/sandbox_proxy/addons/gate.py | .py | """Gate addon: enforces approval policy on identified sandbox egress.
Fail-closed: identity, body-size cap, and unidentified-sandbox checks.
Fail-open: `RequestEvaluator` exceptions and non-matching action types.
"""
import asyncio
import base64
import binascii
import ipaddress
import operator
import socket
import th... | 1,338 | 55,033 |
onyx | backend/onyx/redis/tenant_redis_client.py | .py | """Composition-based tenant-aware Redis client.
Replaces the old ``__getattribute__``-based ``TenantRedis`` (a ``redis.Redis``
subclass that wrapped a hand-maintained allowlist of methods) with an explicit,
hand-written client built by composition. Every public method that touches a key
prefixes it explicitly. Calling... | 1,357 | 48,755 |
onyx | backend/onyx/redis/redis_hierarchy.py | .py | """Redis cache operations for hierarchy node ancestor resolution.
This module provides a Redis-based cache for hierarchy node parent relationships,
enabling fast ancestor path resolution without repeated database queries.
The cache stores node_id -> parent_id mappings for all hierarchy nodes of a given
source type. W... | 587 | 19,581 |
onyx | backend/onyx/redis/redis_utils.py | .py | from onyx.redis.redis_connector_delete import RedisConnectorDelete
from onyx.redis.redis_connector_doc_perm_sync import RedisConnectorPermissionSync
from onyx.redis.redis_connector_prune import RedisConnectorPrune
from onyx.redis.redis_document_set import RedisDocumentSet
from onyx.redis.redis_usergroup import RedisUse... | 22 | 834 |
onyx | backend/onyx/redis/redis_connector_delete.py | .py | import time
from datetime import datetime
from typing import cast
from uuid import uuid4
from celery import Celery
from pydantic import BaseModel
from redis.lock import Lock as RedisLock
from sqlalchemy.orm import Session
from onyx.configs.app_configs import DB_YIELD_PER_DEFAULT
from onyx.configs.constants import (
... | 185 | 6,723 |
onyx | backend/onyx/redis/redis_connector_index.py | .py | from datetime import datetime
from pydantic import BaseModel
class RedisConnectorIndexPayload(BaseModel):
index_attempt_id: int | None
started: datetime | None
submitted: datetime
celery_task_id: str | None
| 11 | 226 |
onyx | backend/onyx/redis/redis_connector_doc_perm_sync.py | .py | import time
from datetime import datetime
from logging import Logger
from typing import Any, NamedTuple, cast
from pydantic import BaseModel
from redis.lock import Lock as RedisLock
from onyx.access.models import DocExternalAccess, ElementExternalAccess
from onyx.configs.constants import (
CELERY_GENERIC_BEAT_LOC... | 300 | 11,098 |
onyx | backend/onyx/redis/redis_pool.py | .py | import asyncio
import json
import threading
from typing import Any, Optional, cast
import redis
from fastapi import Request
from redis import asyncio as aioredis
from redis.asyncio.sentinel import Sentinel as AsyncSentinel
from redis.backoff import ExponentialBackoff
from redis.client import Redis
from redis.exception... | 675 | 24,848 |
onyx | backend/onyx/redis/redis_connector_ext_group_sync.py | .py | from datetime import datetime
from typing import cast
from celery import Celery
from pydantic import BaseModel
from redis.lock import Lock as RedisLock
from sqlalchemy.orm import Session
from onyx.configs.constants import OnyxRedisConstants
from onyx.redis.redis_pool import SCAN_ITER_COUNT_DEFAULT
from onyx.redis.ten... | 192 | 6,841 |
onyx | backend/onyx/redis/redis_connector_stop.py | .py | from onyx.redis.tenant_redis_client import TenantRedisClient
class RedisConnectorStop:
"""Manages interactions with redis for stop signaling. Should only be accessed
through RedisConnector."""
PREFIX = "connectorstop"
FENCE_PREFIX = f"{PREFIX}_fence"
FENCE_TTL = 7 * 24 * 60 * 60 # 7 days - defen... | 52 | 1,688 |
onyx | backend/onyx/redis/lock_context.py | .py | import time
from collections.abc import Generator
from contextlib import contextmanager
from logging import Logger, LoggerAdapter
from redis.lock import Lock
from onyx.redis.redis_pool import get_shared_redis_client
class RedisSharedLockAcquisitionError(Exception):
"""Raised when a Redis shared lock cannot be a... | 81 | 2,843 |
onyx | backend/onyx/redis/redis_connector_prune.py | .py | import time
from datetime import datetime
from typing import cast
from uuid import uuid4
from celery import Celery
from pydantic import BaseModel
from redis.lock import Lock as RedisLock
from sqlalchemy.orm import Session
from onyx.configs.app_configs import PRUNE_FAILURE_BACKOFF_SECONDS
from onyx.configs.constants i... | 281 | 10,602 |
onyx | backend/onyx/redis/redis_docprocessing.py | .py | from typing import cast
from onyx.redis.tenant_redis_client import TenantRedisClient
# Safety-net TTL against leaked keys if cleanup() fails silently. Long enough
# that no legitimate sync will hit it; keys are normally deleted by cleanup().
_COUNTER_TTL_SECONDS = 15 * 24 * 3600 # 15 days
# Why Lua scripts for decr... | 102 | 4,192 |
onyx | backend/onyx/redis/redis_usergroup.py | .py | import time
from typing import cast
from uuid import uuid4
from celery import Celery
from redis.lock import Lock as RedisLock
from sqlalchemy.orm import Session
from onyx.configs.app_configs import DB_YIELD_PER_DEFAULT
from onyx.configs.constants import (
CELERY_VESPA_SYNC_BEAT_LOCK_TIMEOUT,
OnyxCeleryPriorit... | 130 | 4,418 |
onyx | backend/onyx/redis/iam_auth.py | .py | """
Redis IAM Authentication Module
This module provides Redis IAM authentication functionality for AWS ElastiCache.
Unlike RDS IAM auth, Redis IAM auth relies on IAM roles and policies rather than
generating authentication tokens.
Key functions:
- configure_redis_iam_auth: Configure Redis connection parameters for IAM... | 46 | 1,873 |
onyx | backend/onyx/redis/redis_document_set.py | .py | import time
from typing import cast
from uuid import uuid4
from celery import Celery
from redis.lock import Lock as RedisLock
from sqlalchemy.orm import Session
from onyx.configs.app_configs import DB_YIELD_PER_DEFAULT
from onyx.configs.constants import (
CELERY_VESPA_SYNC_BEAT_LOCK_TIMEOUT,
OnyxCeleryPriorit... | 114 | 4,028 |
onyx | backend/onyx/redis/redis_connector.py | .py | from onyx.redis.redis_connector_delete import RedisConnectorDelete
from onyx.redis.redis_connector_doc_perm_sync import RedisConnectorPermissionSync
from onyx.redis.redis_connector_ext_group_sync import RedisConnectorExternalGroupSync
from onyx.redis.redis_connector_prune import RedisConnectorPrune
from onyx.redis.redi... | 85 | 3,307 |
onyx | backend/onyx/redis/redis_object_helper.py | .py | from abc import ABC, abstractmethod
from celery import Celery
from redis.lock import Lock as RedisLock
from sqlalchemy.orm import Session
from onyx.redis.redis_pool import get_redis_client
from onyx.redis.tenant_redis_client import TenantRedisClient
class RedisObjectHelper(ABC):
PREFIX = "base"
FENCE_PREFIX... | 98 | 3,179 |
onyx | backend/onyx/redis/redis_tenant_work_gating.py | .py | """Redis helpers for the tenant work-gating feature.
One sorted set `active_tenants` under the cloud Redis tenant tracks the last
time each tenant was observed doing work. The fanout generator reads the set
(filtered to entries within a TTL window) and skips tenants that haven't been
active recently.
All public funct... | 190 | 6,590 |
onyx | backend/onyx/redis/redis_connector_utils.py | .py | from sqlalchemy.orm import Session
from onyx.db.connector_credential_pair import get_connector_credential_pair
from onyx.db.enums import ConnectorCredentialPairStatus, TaskStatus
from onyx.db.models import TaskQueueState
from onyx.redis.redis_connector import RedisConnector
from onyx.server.documents.models import Del... | 60 | 1,789 |
onyx | backend/alembic/run_multitenant_migrations.py | .py | #!/usr/bin/env python3
"""Parallel Alembic Migration Runner
Upgrades tenant schemas to head in batched, parallel alembic subprocesses.
Each subprocess handles a batch of schemas (via ``-x schemas=a,b,c``),
reducing per-process overhead compared to one-schema-per-process.
Usage examples::
# defaults: 6 workers, 5... | 318 | 10,605 |
onyx | backend/alembic/env.py | .py | from onyx.db.engine.iam_auth import make_provide_iam_token_async
from onyx.db.engine.pg_ssl import create_pg_ssl_context
from onyx.configs.app_configs import USE_IAM_AUTH
from onyx.configs.app_configs import POSTGRES_HOST
from onyx.configs.app_configs import POSTGRES_PORT
from onyx.configs.app_configs import POSTGRES_U... | 556 | 20,208 |
onyx | backend/alembic/versions/4d58345da04a_lowercase_user_emails.py | .py | """lowercase_user_emails
Revision ID: 4d58345da04a
Revises: f1ca58b2f2ec
Create Date: 2025-01-29 07:48:46.784041
"""
import logging
from typing import cast
from alembic import op
from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql import text
# revision identifiers, used by Alembic.
revision = "4d58345da0... | 65 | 1,952 |
onyx | backend/alembic/versions/1cb59a95b250_add_security_settings_table.py | .py | """add security_settings table
Revision ID: 1cb59a95b250
Revises: 99ecd56cb2ce
Create Date: 2026-06-09 17:36:09.181328
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "1cb59a95b250"
down_revision = "99ecd56cb2ce"
bran... | 57 | 1,823 |
onyx | backend/alembic/versions/05c07bf07c00_add_search_doc_relevance_details.py | .py | """add search doc relevance details
Revision ID: 05c07bf07c00
Revises: b896bbd0d5a7
Create Date: 2024-07-10 17:48:15.886653
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "05c07bf07c00"
down_revision = "b896bbd0d5a7"
branch_labels: None = None
depends_on: None... | 33 | 715 |
onyx | backend/alembic/versions/d5c86e2c6dc6_add_cascade_delete_to_search_query_user_.py | .py | """add_cascade_delete_to_search_query_user_id
Revision ID: d5c86e2c6dc6
Revises: 90b409d06e50
Create Date: 2026-02-04 16:05:04.749804
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "d5c86e2c6dc6"
down_revision = "90b409d06e50"
branch_labels = None
depends_on = None
def upgrade() ->... | 35 | 819 |
onyx | backend/alembic/versions/1a03d2c2856b_add_indexes_to_document__tag.py | .py | """Add indexes to document__tag
Revision ID: 1a03d2c2856b
Revises: 9c00a2bccb83
Create Date: 2025-02-18 10:45:13.957807
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "1a03d2c2856b"
down_revision = "9c00a2bccb83"
branch_labels: None = None
depends_on: None = None
def upgrade() -> N... | 29 | 566 |
onyx | backend/alembic/versions/8d1297b43210_add_cache_creation_tokens_to_user_usage.py | .py | """add cache creation tokens to user usage
Revision ID: 8d1297b43210
Revises: 3350a25df58e
Create Date: 2026-07-31 15:45:02.165673
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "8d1297b43210"
down_revision = "3350a25df58e"
branch_labels = None
depends_on = No... | 33 | 636 |
onyx | backend/alembic/versions/503883791c39_add_effective_permissions.py | .py | """add_effective_permissions
Adds a JSONB column `effective_permissions` to the user table to store
directly granted permissions (e.g. ["admin"] or ["basic"]). Implied
permissions are expanded at read time, not stored.
Backfill: joins user__user_group β permission_grant to collect each
user's granted permissions into... | 104 | 2,704 |
onyx | backend/alembic/versions/5e84129c8be3_add_docs_indexed_column_to_index_.py | .py | """Add docs_indexed_column + time_started to index_attempt table
Revision ID: 5e84129c8be3
Revises: e6a4bbc13fe4
Create Date: 2023-08-10 21:43:09.069523
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "5e84129c8be3"
down_revision = "e6a4bbc13fe4"
branch_labels:... | 37 | 795 |
onyx | backend/alembic/versions/3a78dba1080a_user_file_legacy_data_cleanup.py | .py | """Migration 5: User file legacy data cleanup
Revision ID: 3a78dba1080a
Revises: 7cc3fcc116c1
Create Date: 2025-09-22 10:04:27.986294
This migration removes legacy user-file documents and connector_credential_pairs.
It performs bulk deletions of obsolete data after the UUID migration.
"""
from alembic import op
impo... | 296 | 10,098 |
onyx | backend/alembic/versions/8188861f4e92_csv_to_tabular_chat_file_type.py | .py | """csv to tabular chat file type
Revision ID: 8188861f4e92
Revises: d8cdfee5df80
Create Date: 2026-03-31 19:23:05.753184
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "8188861f4e92"
down_revision = "d8cdfee5df80"
branch_labels = None
depends_on = None
def upgrade() -> None:
op... | 50 | 1,185 |
onyx | backend/alembic/versions/800f48024ae9_add_id_to_connectorcredentialpair.py | .py | """Add ID to ConnectorCredentialPair
Revision ID: 800f48024ae9
Revises: 767f1c2a00eb
Create Date: 2023-09-19 16:13:42.299715
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.schema import Sequence, CreateSequence
# revision identifiers, used by Alembic.
revision = "800f48024ae9"
down_revision = "7... | 62 | 1,771 |
onyx | backend/alembic/versions/90e3b9af7da4_tag_fix.py | .py | """tag-fix
Revision ID: 90e3b9af7da4
Revises: 62c3a055a141
Create Date: 2025-08-01 20:58:14.607624
"""
import json
import logging
import os
from typing import cast
from typing import Generator
from alembic import op
import sqlalchemy as sa
from onyx.document_index.vespa_constants import DOCUMENT_ID_ENDPOINT
from ... | 321 | 9,806 |
onyx | backend/alembic/versions/1c36b3dc2f4e_add_full_exception_trace_to_permission_.py | .py | """add full_exception_trace to permission sync attempts
Revision ID: 1c36b3dc2f4e
Revises: f0db5f1c6370
Create Date: 2026-05-06 16:18:40.855449
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "1c36b3dc2f4e"
down_revision = "f0db5f1c6370"
branch_labels = None
de... | 33 | 824 |
onyx | backend/alembic/versions/a1b2c3d4e5f6_add_license_table.py | .py | """add license table
Revision ID: a1b2c3d4e5f6
Revises: a01bf2971c5d
Create Date: 2025-12-04 10:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "a1b2c3d4e5f6"
down_revision = "a01bf2971c5d"
branch_labels = None
depends_on = None
def upgrade() -> ... | 50 | 1,132 |
onyx | backend/alembic/versions/b896bbd0d5a7_backfill_is_internet_data_to_false.py | .py | """backfill is_internet data to False
Revision ID: b896bbd0d5a7
Revises: 44f856ae2a4a
Create Date: 2024-07-16 15:21:05.718571
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "b896bbd0d5a7"
down_revision = "44f856ae2a4a"
branch_labels: None = None
depends_on: None = None
def upgrade(... | 24 | 453 |
onyx | backend/alembic/versions/62c3a055a141_add_file_names_to_file_connector_config.py | .py | """add file names to file connector config
Revision ID: 62c3a055a141
Revises: 3fc5d75723b3
Create Date: 2025-07-30 17:01:24.417551
"""
from alembic import op
import sqlalchemy as sa
import json
import os
import logging
# revision identifiers, used by Alembic.
revision = "62c3a055a141"
down_revision = "3fc5d75723b3"... | 122 | 3,357 |
onyx | backend/alembic/versions/8405ca81cc83_notifications_constraint.py | .py | """notifications constraint, sort index, and cleanup old notifications
Revision ID: 8405ca81cc83
Revises: a3c1a7904cd0
Create Date: 2026-01-07 16:43:44.855156
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "8405ca81cc83"
down_revision = "a3c1a7904cd0"
branch_labels = None
depends_on ... | 45 | 1,492 |
onyx | backend/alembic/versions/b72ed7a5db0e_remove_description_from_starter_messages.py | .py | """remove description from starter messages
Revision ID: b72ed7a5db0e
Revises: 33cb72ea4d80
Create Date: 2024-11-03 15:55:28.944408
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "b72ed7a5db0e"
down_revision = "33cb72ea4d80"
branch_labels = None
depends_on = N... | 45 | 1,111 |
onyx | backend/alembic/versions/3260759d6965_add_incognito_to_user_file.py | .py | """add incognito columns to user_file
Revision ID: 3260759d6965
Revises: c7f1a9d4e206
Create Date: 2026-08-10 13:00:00.000000
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "3260759d6965"
down_revision = "c7f1a9d4e206"
branch_labels = None
depends_on = None
... | 49 | 1,315 |
onyx | backend/alembic/versions/5c7fdadae813_match_any_keywords_flag_for_standard_.py | .py | """match_any_keywords flag for standard answers
Revision ID: 5c7fdadae813
Revises: efb35676026c
Create Date: 2024-09-13 18:52:59.256478
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "5c7fdadae813"
down_revision = "efb35676026c"
branch_labels = None
depends_on... | 37 | 851 |
onyx | backend/alembic/versions/77d07dffae64_forcibly_remove_more_enum_types_from_.py | .py | """forcibly remove more enum types from postgres
Revision ID: 77d07dffae64
Revises: d61e513bef0a
Create Date: 2023-11-01 12:33:01.999617
"""
from alembic import op
from sqlalchemy import String
# revision identifiers, used by Alembic.
revision = "77d07dffae64"
down_revision = "d61e513bef0a"
branch_labels: None = No... | 36 | 1,252 |
onyx | backend/alembic/versions/ea418a384b9d_add_document_content_hash.py | .py | """add content_hash to document
Revision ID: ea418a384b9d
Revises: 9618d5038140
Create Date: 2026-05-18 12:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = "ea418a384b9d"
down_revision = "9618d5038140"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column(
... | 27 | 478 |
onyx | backend/alembic/versions/cec7ec36c505_kgentity_parent.py | .py | """kgentity_parent
Revision ID: cec7ec36c505
Revises: 495cb26ce93e
Create Date: 2025-06-07 20:07:46.400770
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "cec7ec36c505"
down_revision = "495cb26ce93e"
branch_labels = None
depends_on = None
def upgrade() -> No... | 29 | 612 |
onyx | backend/alembic/versions/b388730a2899_nullable_preferences.py | .py | """nullable preferences
Revision ID: b388730a2899
Revises: 1a03d2c2856b
Create Date: 2025-02-17 18:49:22.643902
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "b388730a2899"
down_revision = "1a03d2c2856b"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.alter_co... | 32 | 876 |
onyx | backend/alembic/versions/3a9b8d7c6e5f_add_mcp_known_provider_fields.py | .py | """add mcp known-provider oauth fields
Revision ID: 3a9b8d7c6e5f
Revises: 4d545225fd82
Create Date: 2026-05-31 13:40:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from onyx.db.enums import MCPOAuthProviderMode
# revision identifiers, used by Alembic.
revisi... | 60 | 1,629 |
onyx | backend/alembic/versions/7cb492013621_code_interpreter_server_model.py | .py | """code interpreter server model
Revision ID: 7cb492013621
Revises: 0bb4558f35df
Create Date: 2026-02-22 18:54:54.007265
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "7cb492013621"
down_revision = "0bb4558f35df"
branch_labels = None
depends_on = None
def u... | 31 | 640 |
onyx | backend/alembic/versions/570282d33c49_track_onyxbot_explicitly.py | .py | """Track Onyxbot Explicitly
Revision ID: 570282d33c49
Revises: 7547d982db8f
Create Date: 2024-05-04 17:49:28.568109
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "570282d33c49"
down_revision = "7547d982db8f"
branch_labels: None = None
depends_on: None = None
... | 29 | 673 |
onyx | backend/alembic/versions/d961aca62eb3_update_status_length.py | .py | """Update status length
Revision ID: d961aca62eb3
Revises: cf90764725d8
Create Date: 2025-03-23 16:10:05.683965
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "d961aca62eb3"
down_revision = "cf90764725d8"
branch_labels = None
depends_on = None
def upgrade() ... | 57 | 1,474 |
onyx | backend/alembic/versions/2c2430828bdf_add_unique_constraint_to_inputprompt_.py | .py | """add_unique_constraint_to_inputprompt_prompt_user_id
Revision ID: 2c2430828bdf
Revises: fb80bdd256de
Create Date: 2026-01-20 16:01:54.314805
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "2c2430828bdf"
down_revision = "fb80bdd256de"
branch_labels = None
depends_on = None
def upg... | 40 | 1,187 |
onyx | backend/alembic/versions/b51c6844d1df_seed_memory_tool.py | .py | """seed_memory_tool and add enable_memory_tool to user
Revision ID: b51c6844d1df
Revises: 93c15d6a6fbb
Create Date: 2026-02-11 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "b51c6844d1df"
down_revision = "93c15d6a6fbb"
branch_labels = None
dep... | 77 | 1,918 |
onyx | backend/alembic/versions/cf90764725d8_larger_refresh_tokens.py | .py | """larger refresh tokens
Revision ID: cf90764725d8
Revises: 4794bc13e484
Create Date: 2025-04-04 10:56:39.769294
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "cf90764725d8"
down_revision = "4794bc13e484"
branch_labels = None
depends_on = None
def upgrade()... | 25 | 512 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.