Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions .config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,33 @@ properties:
enum: ["openai", "ollama"]
model:
type: string
description: "e.g. gpt-4o-mini, gpt-5.6-luna. LLM_MODEL overrides this."
description: "e.g. gpt-6-luna (the default), gpt-6-sol. LLM_MODEL overrides this."
base_url:
type: string
description: "OpenAI-compatible endpoint, for self-hosted models."
temperature:
type: number
description: >-
Almost always leave unset: the value a model requires is derived. Set
it only for a model the derived table has not met. A value the model
refuses stops the server at startup.
Ollama only. With provider openai it stops the server at startup:
current OpenAI models accept only their own default temperature, so
none is sent. Set reasoning_effort instead.
reasoning_effort:
type: string
enum: ["none", "minimal", "low", "medium", "high", "xhigh"]
description: >-
OpenAI only; unset means low. Sent on every call except the answer:
rephrase, safety, language, intent, query expansion, grading. Which
levels a model accepts varies, so startup sends one request with this
level and stops, quoting the levels the API lists, if the model
rejects it.
answer_reasoning_effort:
type: string
enum: ["none", "minimal", "low", "medium", "high", "xhigh"]
description: >-
OpenAI only; unset means medium. Sent on the calls whose text reaches
the user as the answer: the answer, live-data lookups, the reply to a
refused question, and analysis summaries. Checked against the API at
startup the same way.
additionalProperties: false
messages:
type: object
Expand Down
112 changes: 0 additions & 112 deletions bin/probe_model_temperature

This file was deleted.

36 changes: 29 additions & 7 deletions bin/retrieval_baseline
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,27 @@ from typing import Any

import nltk
from dotenv import load_dotenv
from langchain_classic.retrievers.self_query.base import SelfQueryRetriever
from langchain_chroma.vectorstores import Chroma
from langchain_classic.retrievers.self_query.base import SelfQueryRetriever
from langchain_community.retrievers import BM25Retriever
from langchain_core.documents import Document
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.retrievers import BaseRetriever
from nltk.tokenize import word_tokenize


# Run from anywhere without setting PYTHONPATH, like the other bin/ scripts.
# The Dockerfile and CI both set it (`/app/src`, `./bin:./src`), so importing
# worked there and nowhere else -- including in this script's own documented
# usage.
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))

from agent.models import get_embedding, get_llm
from agent.graph import (
DEFAULT_LLM_MODEL,
ModelConfigError,
build_llm,
resolve_model_parameters,
)
from agent.models import get_embedding
from data_generation.metadata_csv_loader import MetaDataCSVLoader
from retrievers.csv_chroma import (
VECTOR_OVERFETCH,
Expand Down Expand Up @@ -78,9 +84,9 @@ def doc_id(doc: Document) -> str:


def build_retrievers(
embeddings_dir: Path, collection: str, k: int, *, with_selfquery: bool
embeddings_dir: Path, collection: str, k: int, *, llm: BaseChatModel | None
) -> dict[str, BaseRetriever]:
llm = get_llm("openai", "gpt-4o-mini")
"""`llm` is the self-query model; None leaves self-query out."""
embedding = get_embedding("openai", "text-embedding-3-large")

csv_path = embeddings_dir / "csv_files" / f"{collection}.csv"
Expand Down Expand Up @@ -123,7 +129,7 @@ def build_retrievers(
# The plain semantic retriever: similarity search with no LLM in the loop.
"vector": vectordb.as_retriever(search_kwargs={"k": overfetch}),
}
if with_selfquery:
if llm is not None:
retrievers["selfquery"] = SelfQueryRetriever.from_llm(
llm=llm,
vectorstore=vectordb,
Expand Down Expand Up @@ -153,11 +159,27 @@ def capture(args: argparse.Namespace) -> None:
file=sys.stderr,
)

# Built once, and only when asked for: it used to be built per collection
# whether or not self-query ran. The built-in default model with no deployment
# config, so a baseline does not move when one deployment's config.yml
# changes. Checked against the API before any question is asked.
selfquery_llm: BaseChatModel | None = None
if args.with_selfquery:
try:
selfquery_llm = build_llm(
"openai",
DEFAULT_LLM_MODEL,
parameters=resolve_model_parameters("openai", None),
check=True,
)
except ModelConfigError as exc:
raise SystemExit(str(exc)) from None

result: Capture = {q: {} for q in questions}
for collection in collections:
print(f" {collection}: building retrievers...", file=sys.stderr)
retrievers = build_retrievers(
embeddings_dir, collection, args.k, with_selfquery=args.with_selfquery
embeddings_dir, collection, args.k, llm=selfquery_llm
)
for i, question in enumerate(questions, start=1):
print(f" [{i}/{len(questions)}] {question[:60]}", file=sys.stderr)
Expand Down
9 changes: 8 additions & 1 deletion config_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ profiles:
#
#llm:
# provider: openai
# model: gpt-4o-mini
# model: gpt-6-luna
# # OpenAI only. Two levels: the answer the user reads (unset means medium),
# # and every other call -- rephrase, safety, language, intent, query
# # expansion, grading (unset means low). Which levels a model accepts varies,
# # and startup checks yours against the API. No temperature: OpenAI models
# # use only their own default, and setting one stops startup.
# reasoning_effort: low
# answer_reasoning_effort: medium
#
# Do not add an embedding model here. It comes from the bundle that built the
# vectors; setting it to anything else makes retrieval silently meaningless.
Expand Down
16 changes: 8 additions & 8 deletions deploy/beta/env.beta.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ CHAINLIT_URL=https://beta.reactome.org
# bundle, which is what the stored vectors were produced with. Setting it to
# anything else makes retrieval meaningless.
#EMBEDDING_MODEL=
# LLM used for answers; defaults to gpt-4o-mini.
# gpt-5.6-luna is verified to work end to end. It answers with noticeably more
# grounding in the retrieved Reactome records, and takes roughly twice as long
# per question (41s vs 22s, averaged over three questions).
# LLM used for answers; defaults to gpt-6-luna. Any current OpenAI model works
# with no other setting. Startup sends it one request and refuses to start if the
# API rejects its parameters -- including gpt-4o, gpt-4o-mini, gpt-4.1 and
# gpt-4.1-mini, which take no reasoning effort.
#LLM_MODEL=
# Sampling temperature. Leave unset: it defaults to 0.0, except for the
# gpt-5.5/5.6/6 families, which accept only their own default of 1 and return a
# 400 for anything else. Set this only for a model that rule does not yet know
# about; see resolve_temperature in src/agent/graph.py.
# Ollama only. With an OpenAI model this stops startup: current OpenAI models
# accept only their own default temperature, so none is sent. To change how
# much an OpenAI model reasons, set llm.reasoning_effort and
# llm.answer_reasoning_effort in config.yml.
#LLM_TEMPERATURE=

# The answer endpoint verifies the website's caller token against this public
Expand Down
16 changes: 8 additions & 8 deletions env_template
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ TAVILY_API_KEY=
# bundle, which is what the stored vectors were produced with. Setting it to
# anything else makes retrieval meaningless.
#EMBEDDING_MODEL=
# LLM used for answers; defaults to gpt-4o-mini.
# gpt-5.6-luna is verified to work end to end. It answers with noticeably more
# grounding in the retrieved Reactome records, and takes roughly twice as long
# per question (41s vs 22s, averaged over three questions).
# LLM used for answers; defaults to gpt-6-luna. Any current OpenAI model works
# with no other setting. Startup sends it one request and refuses to start if the
# API rejects its parameters -- including gpt-4o, gpt-4o-mini, gpt-4.1 and
# gpt-4.1-mini, which take no reasoning effort.
#LLM_MODEL=
# Sampling temperature. Leave unset: it defaults to 0.0, except for the
# gpt-5.5/5.6/6 families, which accept only their own default of 1 and return a
# 400 for anything else. Set this only for a model that rule does not yet know
# about; see resolve_temperature in src/agent/graph.py.
# Ollama only. With an OpenAI model this stops startup: current OpenAI models
# accept only their own default temperature, so none is sent. To change how
# much an OpenAI model reasons, set llm.reasoning_effort and
# llm.answer_reasoning_effort in config.yml.
#LLM_TEMPERATURE=

# Locale and timezone for the Postgres container's initdb (ICU collation).
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ langchain-classic = "^1.0.8"
# Same: data_generation imports RecursiveCharacterTextSplitter from it.
langchain-text-splitters = "^1.1.2"
# 2.x, required by langchain-openai 1.x (openai>=2.45). Used directly only by
# bin/probe_model_temperature, for models.list().
# tests/agent/test_model_parameters.py, to build the API errors the startup check
# reads.
openai = "^2.45.0"
# Held below 1.0, and langchain-chroma below 1.0 with it. chromadb 1.x opens a
# 0.5/0.6 bundle by migrating its sqlite sysdb in place (9 -> 10), which needs
Expand Down
Loading
Loading