Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
CONFIG_INGESTER,
CONFIG_LANGUAGE_PICKER_ENABLED,
CONFIG_OPENAI_CLIENT,
CONFIG_QUERY_REWRITING_ENABLED,
CONFIG_SEARCH_CLIENT,
CONFIG_SEMANTIC_RANKER_DEPLOYED,
CONFIG_SPEECH_INPUT_ENABLED,
Expand Down Expand Up @@ -291,6 +292,7 @@ def config():
{
"showGPT4VOptions": current_app.config[CONFIG_GPT4V_DEPLOYED],
"showSemanticRankerOption": current_app.config[CONFIG_SEMANTIC_RANKER_DEPLOYED],
"showQueryRewritingOption": current_app.config[CONFIG_QUERY_REWRITING_ENABLED],
"showVectorOption": current_app.config[CONFIG_VECTOR_SEARCH_ENABLED],
"showUserUpload": current_app.config[CONFIG_USER_UPLOAD_ENABLED],
"showLanguagePicker": current_app.config[CONFIG_LANGUAGE_PICKER_ENABLED],
Expand Down Expand Up @@ -453,6 +455,7 @@ async def setup_clients():
AZURE_SEARCH_QUERY_LANGUAGE = os.getenv("AZURE_SEARCH_QUERY_LANGUAGE") or "en-us"
AZURE_SEARCH_QUERY_SPELLER = os.getenv("AZURE_SEARCH_QUERY_SPELLER") or "lexicon"
AZURE_SEARCH_SEMANTIC_RANKER = os.getenv("AZURE_SEARCH_SEMANTIC_RANKER", "free").lower()
AZURE_SEARCH_QUERY_REWRITING = os.getenv("AZURE_SEARCH_QUERY_REWRITING", "false").lower()

AZURE_SPEECH_SERVICE_ID = os.getenv("AZURE_SPEECH_SERVICE_ID")
AZURE_SPEECH_SERVICE_LOCATION = os.getenv("AZURE_SPEECH_SERVICE_LOCATION")
Expand Down Expand Up @@ -634,6 +637,9 @@ async def setup_clients():

current_app.config[CONFIG_GPT4V_DEPLOYED] = bool(USE_GPT4V)
current_app.config[CONFIG_SEMANTIC_RANKER_DEPLOYED] = AZURE_SEARCH_SEMANTIC_RANKER != "disabled"
current_app.config[CONFIG_QUERY_REWRITING_ENABLED] = (
AZURE_SEARCH_QUERY_REWRITING == "true" and AZURE_SEARCH_SEMANTIC_RANKER != "disabled"
)
current_app.config[CONFIG_VECTOR_SEARCH_ENABLED] = os.getenv("USE_VECTORS", "").lower() != "false"
current_app.config[CONFIG_USER_UPLOAD_ENABLED] = bool(USE_USER_UPLOAD)
current_app.config[CONFIG_LANGUAGE_PICKER_ENABLED] = ENABLE_LANGUAGE_PICKER
Expand Down
2 changes: 2 additions & 0 deletions app/backend/approaches/approach.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ async def search(
use_semantic_captions: bool,
minimum_search_score: Optional[float],
minimum_reranker_score: Optional[float],
use_query_rewriting: Optional[bool] = None,
) -> List[Document]:
search_text = query_text if use_text_search else ""
search_vectors = vectors if use_vector_search else []
Expand All @@ -158,6 +159,7 @@ async def search(
filter=filter,
top=top,
query_caption="extractive|highlight-false" if use_semantic_captions else None,
query_rewrites="generative" if use_query_rewriting else None,
vector_queries=search_vectors,
query_type=QueryType.SEMANTIC,
query_language=self.query_language,
Expand Down
3 changes: 3 additions & 0 deletions app/backend/approaches/chatreadretrieveread.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async def run_until_final_call(
use_vector_search = overrides.get("retrieval_mode") in ["vectors", "hybrid", None]
use_semantic_ranker = True if overrides.get("semantic_ranker") else False
use_semantic_captions = True if overrides.get("semantic_captions") else False
use_query_rewriting = True if overrides.get("query_rewriting") else False
top = overrides.get("top", 3)
minimum_search_score = overrides.get("minimum_search_score", 0.0)
minimum_reranker_score = overrides.get("minimum_reranker_score", 0.0)
Expand Down Expand Up @@ -147,6 +148,7 @@ async def run_until_final_call(
use_semantic_captions,
minimum_search_score,
minimum_reranker_score,
use_query_rewriting,
)

# STEP 3: Generate a contextual and content specific answer using the search results and chat history
Expand Down Expand Up @@ -190,6 +192,7 @@ async def run_until_final_call(
{
"use_semantic_captions": use_semantic_captions,
"use_semantic_ranker": use_semantic_ranker,
"use_query_rewriting": use_query_rewriting,
"top": top,
"filter": filter,
"use_vector_search": use_vector_search,
Expand Down
3 changes: 3 additions & 0 deletions app/backend/approaches/chatreadretrievereadvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async def run_until_final_call(
use_text_search = overrides.get("retrieval_mode") in ["text", "hybrid", None]
use_vector_search = overrides.get("retrieval_mode") in ["vectors", "hybrid", None]
use_semantic_ranker = True if overrides.get("semantic_ranker") else False
use_query_rewriting = True if overrides.get("query_rewriting") else False
use_semantic_captions = True if overrides.get("semantic_captions") else False
top = overrides.get("top", 3)
minimum_search_score = overrides.get("minimum_search_score", 0.0)
Expand Down Expand Up @@ -151,6 +152,7 @@ async def run_until_final_call(
use_semantic_captions,
minimum_search_score,
minimum_reranker_score,
use_query_rewriting,
)

# STEP 3: Generate a contextual and content specific answer using the search results and chat history
Expand Down Expand Up @@ -207,6 +209,7 @@ async def run_until_final_call(
{
"use_semantic_captions": use_semantic_captions,
"use_semantic_ranker": use_semantic_ranker,
"use_query_rewriting": use_query_rewriting,
"top": top,
"filter": filter,
"vector_fields": vector_fields,
Expand Down
3 changes: 3 additions & 0 deletions app/backend/approaches/retrievethenread.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async def run(
use_text_search = overrides.get("retrieval_mode") in ["text", "hybrid", None]
use_vector_search = overrides.get("retrieval_mode") in ["vectors", "hybrid", None]
use_semantic_ranker = True if overrides.get("semantic_ranker") else False
use_query_rewriting = True if overrides.get("query_rewriting") else False
use_semantic_captions = True if overrides.get("semantic_captions") else False
top = overrides.get("top", 3)
minimum_search_score = overrides.get("minimum_search_score", 0.0)
Expand All @@ -89,6 +90,7 @@ async def run(
use_semantic_captions,
minimum_search_score,
minimum_reranker_score,
use_query_rewriting,
)

# Process results
Expand Down Expand Up @@ -118,6 +120,7 @@ async def run(
{
"use_semantic_captions": use_semantic_captions,
"use_semantic_ranker": use_semantic_ranker,
"use_query_rewriting": use_query_rewriting,
"top": top,
"filter": filter,
"use_vector_search": use_vector_search,
Expand Down
3 changes: 3 additions & 0 deletions app/backend/approaches/retrievethenreadvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async def run(
use_text_search = overrides.get("retrieval_mode") in ["text", "hybrid", None]
use_vector_search = overrides.get("retrieval_mode") in ["vectors", "hybrid", None]
use_semantic_ranker = True if overrides.get("semantic_ranker") else False
use_query_rewriting = True if overrides.get("query_rewriting") else False
use_semantic_captions = True if overrides.get("semantic_captions") else False
top = overrides.get("top", 3)
minimum_search_score = overrides.get("minimum_search_score", 0.0)
Expand Down Expand Up @@ -108,6 +109,7 @@ async def run(
use_semantic_captions,
minimum_search_score,
minimum_reranker_score,
use_query_rewriting,
)

# Process results
Expand Down Expand Up @@ -145,6 +147,7 @@ async def run(
{
"use_semantic_captions": use_semantic_captions,
"use_semantic_ranker": use_semantic_ranker,
"use_query_rewriting": use_query_rewriting,
"top": top,
"filter": filter,
"vector_fields": vector_fields,
Expand Down
1 change: 1 addition & 0 deletions app/backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CONFIG_AUTH_CLIENT = "auth_client"
CONFIG_GPT4V_DEPLOYED = "gpt4v_deployed"
CONFIG_SEMANTIC_RANKER_DEPLOYED = "semantic_ranker_deployed"
CONFIG_QUERY_REWRITING_ENABLED = "query_rewriting_enabled"
CONFIG_VECTOR_SEARCH_ENABLED = "vector_search_enabled"
CONFIG_SEARCH_CLIENT = "search_client"
CONFIG_OPENAI_CLIENT = "openai_client"
Expand Down
2 changes: 1 addition & 1 deletion app/backend/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tenacity
azure-ai-documentintelligence==1.0.0b4
azure-cognitiveservices-speech
azure-cosmos
azure-search-documents==11.6.0b6
azure-search-documents==11.6.0b9
azure-storage-blob
azure-storage-file-datalake
uvicorn
Expand Down
2 changes: 1 addition & 1 deletion app/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ azure-monitor-opentelemetry==1.6.1
# via -r requirements.in
azure-monitor-opentelemetry-exporter==1.0.0b32
# via azure-monitor-opentelemetry
azure-search-documents==11.6.0b6
azure-search-documents==11.6.0b9
# via -r requirements.in
azure-storage-blob==12.22.0
# via
Expand Down
2 changes: 2 additions & 0 deletions app/frontend/src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type ChatAppRequestOverrides = {
retrieval_mode?: RetrievalMode;
semantic_ranker?: boolean;
semantic_captions?: boolean;
query_rewriting?: boolean;
include_category?: string;
exclude_category?: string;
seed?: number;
Expand Down Expand Up @@ -84,6 +85,7 @@ export type ChatAppRequest = {
export type Config = {
showGPT4VOptions: boolean;
showSemanticRankerOption: boolean;
showQueryRewritingOption: boolean;
showVectorOption: boolean;
showUserUpload: boolean;
showLanguagePicker: boolean;
Expand Down
20 changes: 20 additions & 0 deletions app/frontend/src/components/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export interface SettingsProps {
minimumRerankerScore: number;
useSemanticRanker: boolean;
useSemanticCaptions: boolean;
useQueryRewriting: boolean;
excludeCategory: string;
includeCategory: string;
retrievalMode: RetrievalMode;
useGPT4V: boolean;
gpt4vInput: GPT4VInput;
vectorFieldList: VectorFieldOptions[];
showSemanticRankerOption: boolean;
showQueryRewritingOption: boolean;
showGPT4VOptions: boolean;
showVectorOption: boolean;
useOidSecurityFilter: boolean;
Expand All @@ -51,13 +53,15 @@ export const Settings = ({
minimumRerankerScore,
useSemanticRanker,
useSemanticCaptions,
useQueryRewriting,
excludeCategory,
includeCategory,
retrievalMode,
useGPT4V,
gpt4vInput,
vectorFieldList,
showSemanticRankerOption,
showQueryRewritingOption,
showGPT4VOptions,
showVectorOption,
useOidSecurityFilter,
Expand Down Expand Up @@ -94,6 +98,7 @@ export const Settings = ({
const excludeCategoryFieldId = useId("excludeCategoryField");
const semanticRankerId = useId("semanticRanker");
const semanticRankerFieldId = useId("semanticRankerField");
const queryRewritingFieldId = useId("queryRewritingField");
const semanticCaptionsId = useId("semanticCaptions");
const semanticCaptionsFieldId = useId("semanticCaptionsField");
const useOidSecurityFilterId = useId("useOidSecurityFilter");
Expand Down Expand Up @@ -239,6 +244,21 @@ export const Settings = ({
</>
)}

{showQueryRewritingOption && (
<>
<Checkbox
id={queryRewritingFieldId}
className={styles.settingsSeparator}
checked={useQueryRewriting}
disabled={!useSemanticRanker}
label={t("labels.useQueryRewriting")}
onChange={(_ev, checked) => onChange("useQueryRewriting", !!checked)}
aria-labelledby={queryRewritingFieldId}
onRenderLabel={props => renderLabel(props, queryRewritingFieldId, queryRewritingFieldId, t("helpTexts.useQueryRewriting"))}
/>
</>
)}

{useLogin && (
<>
<Checkbox
Expand Down
3 changes: 3 additions & 0 deletions app/frontend/src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"excludeCategory": "Exclude category",
"useSemanticRanker": "Use semantic ranker for retrieval",
"useSemanticCaptions": "Use semantic captions",
"useQueryRewriting": "Use query rewriting for retrieval",
"useSuggestFollowupQuestions": "Suggest follow-up questions",
"useGPT4V": "Use GPT vision model",
"gpt4VInput": {
Expand Down Expand Up @@ -139,6 +140,8 @@
"Specifies a category to exclude from the search results. There are no categories used in the default data set.",
"useSemanticReranker":
"Enables the Azure AI Search semantic ranker, a model that re-ranks search results based on semantic similarity to the user's query.",
"useQueryRewriting":
"Enables Azure AI Search query rewriting, a process that modifies the user's query to improve search results. Requires semantic ranker to be enabled.",
"useSemanticCaptions":
"Sends semantic captions to the LLM instead of the full search result. A semantic caption is extracted from a search result during the process of semantic ranking.",
"suggestFollowupQuestions": "Asks the LLM to suggest follow-up questions based on the user's query.",
Expand Down
10 changes: 10 additions & 0 deletions app/frontend/src/pages/ask/Ask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function Component(): JSX.Element {
const [retrieveCount, setRetrieveCount] = useState<number>(3);
const [useSemanticRanker, setUseSemanticRanker] = useState<boolean>(true);
const [useSemanticCaptions, setUseSemanticCaptions] = useState<boolean>(false);
const [useQueryRewriting, setUseQueryRewriting] = useState<boolean>(false);
const [useGPT4V, setUseGPT4V] = useState<boolean>(false);
const [gpt4vInput, setGPT4VInput] = useState<GPT4VInput>(GPT4VInput.TextAndImages);
const [includeCategory, setIncludeCategory] = useState<string>("");
Expand All @@ -42,6 +43,7 @@ export function Component(): JSX.Element {
const [useGroupsSecurityFilter, setUseGroupsSecurityFilter] = useState<boolean>(false);
const [showGPT4VOptions, setShowGPT4VOptions] = useState<boolean>(false);
const [showSemanticRankerOption, setShowSemanticRankerOption] = useState<boolean>(false);
const [showQueryRewritingOption, setShowQueryRewritingOption] = useState<boolean>(false);
const [showVectorOption, setShowVectorOption] = useState<boolean>(false);
const [showUserUpload, setShowUserUpload] = useState<boolean>(false);
const [showLanguagePicker, setshowLanguagePicker] = useState<boolean>(false);
Expand Down Expand Up @@ -78,6 +80,8 @@ export function Component(): JSX.Element {
setShowGPT4VOptions(config.showGPT4VOptions);
setUseSemanticRanker(config.showSemanticRankerOption);
setShowSemanticRankerOption(config.showSemanticRankerOption);
setUseQueryRewriting(config.showQueryRewritingOption);
setShowQueryRewritingOption(config.showQueryRewritingOption);
setShowVectorOption(config.showVectorOption);
if (!config.showVectorOption) {
setRetrievalMode(RetrievalMode.Text);
Expand Down Expand Up @@ -126,6 +130,7 @@ export function Component(): JSX.Element {
retrieval_mode: retrievalMode,
semantic_ranker: useSemanticRanker,
semantic_captions: useSemanticCaptions,
query_rewriting: useQueryRewriting,
use_oid_security_filter: useOidSecurityFilter,
use_groups_security_filter: useGroupsSecurityFilter,
vector_fields: vectorFieldList,
Expand Down Expand Up @@ -180,6 +185,9 @@ export function Component(): JSX.Element {
case "useSemanticCaptions":
setUseSemanticCaptions(value);
break;
case "useQueryRewriting":
setUseQueryRewriting(value);
break;
case "excludeCategory":
setExcludeCategory(value);
break;
Expand Down Expand Up @@ -321,13 +329,15 @@ export function Component(): JSX.Element {
minimumRerankerScore={minimumRerankerScore}
useSemanticRanker={useSemanticRanker}
useSemanticCaptions={useSemanticCaptions}
useQueryRewriting={useQueryRewriting}
excludeCategory={excludeCategory}
includeCategory={includeCategory}
retrievalMode={retrievalMode}
useGPT4V={useGPT4V}
gpt4vInput={gpt4vInput}
vectorFieldList={vectorFieldList}
showSemanticRankerOption={showSemanticRankerOption}
showQueryRewritingOption={showQueryRewritingOption}
showGPT4VOptions={showGPT4VOptions}
showVectorOption={showVectorOption}
useOidSecurityFilter={useOidSecurityFilter}
Expand Down
10 changes: 10 additions & 0 deletions app/frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const Chat = () => {
const [retrieveCount, setRetrieveCount] = useState<number>(3);
const [retrievalMode, setRetrievalMode] = useState<RetrievalMode>(RetrievalMode.Hybrid);
const [useSemanticRanker, setUseSemanticRanker] = useState<boolean>(true);
const [useQueryRewriting, setUseQueryRewriting] = useState<boolean>(false);
const [shouldStream, setShouldStream] = useState<boolean>(true);
const [useSemanticCaptions, setUseSemanticCaptions] = useState<boolean>(false);
const [includeCategory, setIncludeCategory] = useState<string>("");
Expand Down Expand Up @@ -76,6 +77,7 @@ const Chat = () => {

const [showGPT4VOptions, setShowGPT4VOptions] = useState<boolean>(false);
const [showSemanticRankerOption, setShowSemanticRankerOption] = useState<boolean>(false);
const [showQueryRewritingOption, setShowQueryRewritingOption] = useState<boolean>(false);
const [showVectorOption, setShowVectorOption] = useState<boolean>(false);
const [showUserUpload, setShowUserUpload] = useState<boolean>(false);
const [showLanguagePicker, setshowLanguagePicker] = useState<boolean>(false);
Expand All @@ -100,6 +102,8 @@ const Chat = () => {
setShowGPT4VOptions(config.showGPT4VOptions);
setUseSemanticRanker(config.showSemanticRankerOption);
setShowSemanticRankerOption(config.showSemanticRankerOption);
setUseQueryRewriting(config.showQueryRewritingOption);
setShowQueryRewritingOption(config.showQueryRewritingOption);
setShowVectorOption(config.showVectorOption);
if (!config.showVectorOption) {
setRetrievalMode(RetrievalMode.Text);
Expand Down Expand Up @@ -197,6 +201,7 @@ const Chat = () => {
retrieval_mode: retrievalMode,
semantic_ranker: useSemanticRanker,
semantic_captions: useSemanticCaptions,
query_rewriting: useQueryRewriting,
suggest_followup_questions: useSuggestFollowupQuestions,
use_oid_security_filter: useOidSecurityFilter,
use_groups_security_filter: useGroupsSecurityFilter,
Expand Down Expand Up @@ -285,6 +290,9 @@ const Chat = () => {
case "useSemanticRanker":
setUseSemanticRanker(value);
break;
case "useQueryRewriting":
setUseQueryRewriting(value);
break;
case "useSemanticCaptions":
setUseSemanticCaptions(value);
break;
Expand Down Expand Up @@ -500,13 +508,15 @@ const Chat = () => {
minimumRerankerScore={minimumRerankerScore}
useSemanticRanker={useSemanticRanker}
useSemanticCaptions={useSemanticCaptions}
useQueryRewriting={useQueryRewriting}
excludeCategory={excludeCategory}
includeCategory={includeCategory}
retrievalMode={retrievalMode}
useGPT4V={useGPT4V}
gpt4vInput={gpt4vInput}
vectorFieldList={vectorFieldList}
showSemanticRankerOption={showSemanticRankerOption}
showQueryRewritingOption={showQueryRewritingOption}
showGPT4VOptions={showGPT4VOptions}
showVectorOption={showVectorOption}
useOidSecurityFilter={useOidSecurityFilter}
Expand Down
Loading
Loading