This commit is contained in:
pablonyx 2025-03-05 11:40:15 -08:00
parent b6e9e65bb8
commit 14766b1b77
8 changed files with 103 additions and 19 deletions

View File

@ -642,14 +642,4 @@ MOCK_LLM_RESPONSE = (
)
# Image processing configurations
ENABLE_IMAGE_EXTRACTION = (
os.environ.get("ENABLE_IMAGE_EXTRACTION", "true").lower() == "true"
)
ENABLE_INDEXING_TIME_IMAGE_ANALYSIS = not (
os.environ.get("DISABLE_INDEXING_TIME_IMAGE_ANALYSIS", "false").lower() == "true"
)
ENABLE_SEARCH_TIME_IMAGE_ANALYSIS = not (
os.environ.get("DISABLE_SEARCH_TIME_IMAGE_ANALYSIS", "false").lower() == "true"
)
IMAGE_ANALYSIS_MAX_SIZE_MB = int(os.environ.get("IMAGE_ANALYSIS_MAX_SIZE_MB", "20"))
DEFAULT_IMAGE_ANALYSIS_MAX_SIZE_MB = 20

View File

@ -0,0 +1,38 @@
from onyx.configs.app_configs import DEFAULT_IMAGE_ANALYSIS_MAX_SIZE_MB
from onyx.server.settings.store import load_settings
def get_image_extraction_and_analysis_enabled():
"""Get image extraction and analysis enabled setting from workspace settings or fallback to environment variable"""
try:
settings = load_settings()
if settings.image_extraction_and_analysis_enabled is not None:
return settings.image_extraction_and_analysis_enabled
except Exception:
pass
return False
def get_search_time_image_analysis_enabled():
"""Get search time image analysis enabled setting from workspace settings or fallback to environment variable"""
try:
settings = load_settings()
if settings.search_time_image_analysis_enabled is not None:
return settings.search_time_image_analysis_enabled
except Exception:
pass
return False
def get_image_analysis_max_size_mb():
"""Get image analysis max size MB setting from workspace settings or fallback to environment variable"""
try:
settings = load_settings()
if settings.image_analysis_max_size_mb is not None:
return settings.image_analysis_max_size_mb
except Exception:
pass
return DEFAULT_IMAGE_ANALYSIS_MAX_SIZE_MB

View File

@ -1,7 +1,7 @@
"""
Mixin for connectors that need vision capabilities.
"""
from onyx.configs.app_configs import ENABLE_INDEXING_TIME_IMAGE_ANALYSIS
from onyx.configs.llm_configs import get_image_extraction_and_analysis_enabled
from onyx.llm.factory import get_default_llm_with_vision
from onyx.llm.interfaces import LLM
from onyx.utils.logger import setup_logger
@ -30,7 +30,7 @@ class VisionEnabledConnector:
Sets self.image_analysis_llm to the LLM instance or None if disabled.
"""
self.image_analysis_llm: LLM | None = None
if ENABLE_INDEXING_TIME_IMAGE_ANALYSIS:
if get_image_extraction_and_analysis_enabled():
try:
self.image_analysis_llm = get_default_llm_with_vision()
if self.image_analysis_llm is None:

View File

@ -10,8 +10,8 @@ from langchain_core.messages import SystemMessage
from onyx.chat.models import SectionRelevancePiece
from onyx.configs.app_configs import BLURB_SIZE
from onyx.configs.app_configs import ENABLE_SEARCH_TIME_IMAGE_ANALYSIS
from onyx.configs.constants import RETURN_SEPARATOR
from onyx.configs.llm_configs import get_search_time_image_analysis_enabled
from onyx.configs.model_configs import CROSS_ENCODER_RANGE_MAX
from onyx.configs.model_configs import CROSS_ENCODER_RANGE_MIN
from onyx.context.search.enums import LLMEvaluationType
@ -413,7 +413,7 @@ def search_postprocessing(
# NOTE: if we don't rerank, we can return the chunks immediately
# since we know this is the final order.
# This way the user experience isn't delayed by the LLM step
if ENABLE_SEARCH_TIME_IMAGE_ANALYSIS:
if get_search_time_image_analysis_enabled():
update_image_sections_with_query(
retrieved_sections, search_query.query, llm
)
@ -456,7 +456,7 @@ def search_postprocessing(
_log_top_section_links(search_query.search_type.value, reranked_sections)
# Add the image processing step here
if ENABLE_SEARCH_TIME_IMAGE_ANALYSIS:
if get_search_time_image_analysis_enabled():
update_image_sections_with_query(
reranked_sections, search_query.query, llm
)

View File

@ -53,6 +53,11 @@ class Settings(BaseModel):
auto_scroll: bool | None = False
query_history_type: QueryHistoryType | None = None
# Image processing settings
image_extraction_and_analysis_enabled: bool | None = False
search_time_image_analysis_enabled: bool | None = False
image_analysis_max_size_mb: int | None = 20
class UserSettings(Settings):
notifications: list[Notification]

View File

@ -47,6 +47,7 @@ def load_settings() -> Settings:
settings.anonymous_user_enabled = anonymous_user_enabled
settings.query_history_type = ONYX_QUERY_HISTORY_TYPE
return settings

View File

@ -26,7 +26,7 @@ export function Checkbox({
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
}) {
return (
<label className="flex text-sm cursor-pointer">
<label className="flex text-xs cursor-pointer">
<input
checked={checked}
onChange={onChange}
@ -34,7 +34,7 @@ export function Checkbox({
className="mr-2 w-3.5 h-3.5 my-auto"
/>
<div>
<Label>{label}</Label>
<Label small>{label}</Label>
{sublabel && <SubLabel>{sublabel}</SubLabel>}
</div>
</label>
@ -208,7 +208,7 @@ export function SettingsForm() {
}
return (
<div>
<div className="flex flex-col pb-8">
{popup}
<Title className="mb-4">Workspace Settings</Title>
<Checkbox
@ -307,6 +307,51 @@ export function SettingsForm() {
</Button>
</>
)}
{/* Image Processing Settings */}
<Title className="mt-8 mb-4">Image Processing</Title>
<div className="flex flex-col gap-2">
<Checkbox
label="Enable Image Extraction and Analysis"
sublabel="Extract and analyze images from documents during indexing. This allows the system to process images and create searchable descriptions of them."
checked={settings.image_extraction_and_analysis_enabled}
onChange={(e) =>
handleToggleSettingsField(
"image_extraction_and_analysis_enabled",
e.target.checked
)
}
/>
<Checkbox
label="Enable Search-time Image Analysis"
sublabel="Analyze images at search time when a user asks about images. This provides more detailed and query-specific image analysis."
checked={settings.search_time_image_analysis_enabled}
onChange={(e) =>
handleToggleSettingsField(
"search_time_image_analysis_enabled",
e.target.checked
)
}
/>
<IntegerInput
label="Maximum Image Size for Analysis (MB)"
sublabel="Images larger than this size will not be analyzed to prevent excessive resource usage."
value={settings.image_analysis_max_size_mb}
onChange={(e) => {
const value = e.target.value ? parseInt(e.target.value) : null;
if (value !== null && !isNaN(value) && value > 0) {
updateSettingField([
{ fieldName: "image_analysis_max_size_mb", newValue: value },
]);
}
}}
id="image-analysis-max-size"
placeholder="Enter maximum size in MB"
/>
</div>
</div>
);
}

View File

@ -21,6 +21,11 @@ export interface Settings {
auto_scroll: boolean;
temperature_override_enabled: boolean;
query_history_type: QueryHistoryType;
// Image processing settings
image_extraction_and_analysis_enabled: boolean;
search_time_image_analysis_enabled: boolean;
image_analysis_max_size_mb: number;
}
export enum NotificationType {