Sign inSign up

denissa4/aiagent-master

By denissa4

Updated 7 months ago

AI agent master branch with llama-index

Image
0

2.3K

denissa4/aiagent-master repository overview

NLSQL Bot + Anomaly Detection & TalkToDocs:Llama-Index

Build locally:

docker build -f Dockerfile -t ai-agent .

Run locally:

docker run --rm -p 8080:80 --env-file .env ai-agent

Mimic Azure web app resource specs:

docker run --rm -p 8080:80 --env-file .env --cpus="2.0" --memory="8g" ai-agent

Azurite Local Blob connection string: DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://host.docker.internal:10000/devstoreaccount1;

NLSQL Envs:
Environment VariableDescriptionUsed With
DatabaseTypeDatabase type options: 'mysql', 'mssql', 'snowflake', 'redshift', 'postgresql', 'bigquery'All
DataSourceFor 'snowflake' analogue of the 'Account' db parameterAll
AccountAlternative to DataSource for snowflake connectionssnowflake
WarehouseWarehouse identifiersnowflake
DbSchemaDatabase schemasnowflake
DbNameDatabase nameAll
DbUserDatabase usernameAll
DbPasswordDatabase passwordAll
DbPortDatabase port numbermysql, postgresql
ActiveDirectoryAuthenticationEnables Azure Active Directory token-based authentication instead of username/password. Accepts: true, True, 1mssql, mysql, postgresql
ClientIdOfUserAssignedIdentityClient ID of a user-assigned managed identity in Azure. When set, uses this identity for AD token retrieval; otherwise falls back to system-assigned identity. Also triggers AD auth if set, even without ActiveDirectoryAuthenticationmssql, mysql, postgresql
ApiEndPointAPI endpoint URLAll
ApiTokenAPI authentication tokenAll
StaticEndPointStatic endpoint URLAll
client_emailService account emailbigquery
token_uriToken URIbigquery
private_keyPrivate key for authenticationbigquery
project_idGoogle Cloud project IDbigquery
Anomaly Detection Envs:
Environment VariableDescription
FromYearStarting year from which to measure trusted data
ToYearThe final year up to which trusted data is measured (inclusive)
CorridorsMode1 = standard mode (flat corridors over given time period, minimum 1 year of data); 2 = seasonal mode (monthly calculated corridors, minimum 2 years' of data)
WindowSizeSize of the rolling window when using seasonal corridors mode (default = 5)
BoundarySensitivitySensitivity for the lower and upper bounds for anomaly detection (mean +- BoundarySensitivity * standard deviation)
EmailAddressEmail address for sending anomaly detection email
EmailPasswordPassword for senders email (app password may need to be used for gmail and outlook accounts)
RecipientEmailEmail addresses of recipients (separated by comma (no space))
AzureAppNameAzure app name where interactive graph files are stored
OpenAiAPIAPI key for OpenAI integration (informative emails)
OpenAiBaseBase URL for OpenAI integration
OpenAiTypeType of OpenAI service (e.g. azure)
OpenAiVersionOpenAI version
OpenAiNameName of OpenAI model to be used
SystemMessageSystem Message for OpenAI for initial context and instructions given to OpenAI model
FrequencyFrequency (in days) for which the anomaly detection should take place
Talk-to-Docs Envs:
Environment VariableDescription
LanguageModelProviderProvider of the language model (accepts: GCP, AWS, AzureOpenAI, HuggingFace) More to be added.
LanguageModelNameName of the LLM ID, e.g. global.anthropic.claude-sonnet-4-5-20250929-v1:0 (If using Sage Maker this will be the Sage Maker endpoint of your model.)
LanguageModelApiKeyAuthentication secret:
- AzureOpenAI/Gemini: API key
- AWS and SageMaker: AWS Secret Access Key
LanguageModelEndpointProvider-specific endpoint or identifier.
- For AzureOpenAI: The Azure OpenAI resource endpoint URL.
- For AWS and SageMaker: AWS Access Key ID.
LanguageModelVersionVersion of the LLM.
- For AzureOpenAI: The model version (e.g. 2025-12-01)
- For AWS and SageMaker: The model region (e.g. us-east-2)
AzureModelDeploymentNameThe deployment name of the Azure-based language model
LanguageModelContextSystem prompt/context given to the LLM for answering document queries
LanguageModelMaxTokensMaximum number of tokens the LLM can generate in a response (default: 2048)
LanguageModelTimeoutTimeout in seconds for LLM requests (default: 300)
LanguageModelTemperatureControls how creative or predictable the AI responses are. Lower values make responses more focused and accurate. (default: 0.4)
StreamingEnable streaming responses from the bot; Options: true, false (default: false)
EmbeddingModelEmbedding model used for vectorising documents and queries (default: BAAI/bge-small-en-v1.5)
AzureStorageAccNameName of the Azure Storage account containing document files
AzureBlobContainerNameName of the Azure Blob Storage container where documents are stored
AzureStorageSasTokenOptional; SAS token for Azure Blob Storage authentication. Falls back to Managed Identity if not provided
ChunkSizeNumber of words per text chunk when splitting documents for embedding (standard RAG mode only) (default: 200)
MaxChunkSizeMaximum number of words per text chunk - If a sentence ender is not found after ChunkSize and before MaxChunkSize, the chunk will be split at MaxChunkSize (standard RAG mode only) (default: 500)
SentenceEndersWhen true, chunks break at sentence endings (!, ?, .) that come after word count, rather than strictly at word count (standard RAG mode only) (default: true)
GraphRagWhen true uses Graph RAG mode, when false uses standard vector search (default: false)
VerboseGraphWhen true adds more verbose graph RAG answer containing sources and patterns (default: false)
AzureModelsStorageAccNameStorage account name for model storage - embedding & LLM models are stored here (default: nlsqlstorage)
AzureModelsBlobContainerNameContainer name for model storage (default: models)
AzureModelsStorageSasToken
StoreHuggingFaceModelsWhen true Hugging Face models will be storred in local models storage after download - if present stored models will be used instead of Hugging Face models (default: true)
RagSearchResultsNumber or results returned to the LLM (Standard RAG and Graph RAG modes) (default: 5)
GraphChunkSizeChunk size in tokens for splitting Graph RAG documents (default: 50000)
GraphMultistepReasoningNumber of recursive reasoning steps for graph queries (default: 1)
CustomGraphTemplateUses a custom Graph RAG prompt template for Graph RAG queries (default: See below)
FormatPromptPart of the system prompt related to response formatting (default: see below)
EmbeddingModelProviderProvider of the embedding model (accepts: AzureOpenAI, HuggingFace) (default: HuggingFace)
EmbeddingModelApiKeyThe API key of the embedding model (AzureOpenAI only) (default: defaults to LanguageModelApiKey environment variable value)
EmbeddingModelVersionThe version of the embedding model (AzureOpenAI only) (default: defaults to LanguageModelVersion environment variable value)
EmbeddingModelEndpointThe endpoint of the embedding model (AzureOpenAI only) (dafault: defaults to LanguageModelEndpoint environment variable value)
AzureEmbeddingModelDeploymentNameThe deployment name of the Azure-based embedding model
GraphModelProviderProvider of the language model used for building Knowledge Graph and Graph triples (accepts: GCP, AWS, AzureOpenAI, HuggingFace). (default: defaults to LanguageModelProvider if not set.)
GraphModelNameName/ID of the LLM used for Knowledge Graph Building. (default: defaults to LanguageModelName if not set.)
GraphModelEndpointProvider-specific endpoint for the Knowledge Graph Building model. For AzureOpenAI: the Azure OpenAI resource endpoint URL. (default: defaults to LanguageModelEndpoint if not set.)
GraphModelApiKeyAuthentication secret for the Knowledge Graph Building model. For AzureOpenAI: API key. (default: defaults to LanguageModelApiKey if not set.)
GraphModelVersionVersion of the Graph RAG LLM. For AzureOpenAI: the model version (e.g. 2024-02-01). (default: defaults to LanguageModelVersion if not set.)
GraphModelTimeoutTimeout in seconds for Graph RAG LLM requests (default: 300)
GraphModelMaxTokensMaximum number of tokens the Graph RAG LLM can generate in a response (default: 8000)
AzureGraphModelDeploymentNameThe deployment name of the Azure-based language model for Knowledge Graph building
ConversationMemoryIf true the language model with retain converstaion history as context for future responses (default: false)
MaxMemoryTokensThe maximum number of tokens reserved for conversation memory (only applies if ConversationMemory is true) (default: 4000)
AwsS3BucketNameThe S3 bucket to read/write from
AwsAccessKeyIdAWS access key
AwsSecretAccessKeyAWS secret key
AwsRegionAWSAWS region (default: us-east-1)
HF_HOMEThe base directory for internal Hugging Face model storage (default: /home/huggingface)
HF_TOKEN(Optional) Hugging Face API token for models that require a authentication.
LLAMA_INDEX_CACHE_DIRThe base directory for internal Llama Index model storage (default: /home/llama_index)
RUN_TESTWhen true runs assertion tests accross all Talk to Docs functions (default: false)
RUN_INTEGRATION_TESTSWhen true initial cloud-based integration tests will run (default: false)
RUN_E2E_TESTSWhen true end-to-end request/response tests will run after app initialization. (default: false)
DIRECT_LINE_SECRETThe Direct Line secret needed for end-to-end tests
INIT_TIMEOUT_SECONDSHow long - in seconds - the app will poll initialization for end-to-end tests (default: 600)
Default Format Prompt:

You must always respond in Markdown and plain text only. Never respond in JSON, code blocks containing JSON, or any other structured data format. Do not include any pre-response tags, metadata, system notes, or explanations about formatting. Respond directly to the user’s request without any introductory or wrapper text.

Default Graph Template:
{% chat role="system" %}
{system_prompt}
## Response Format Rules\n{format_prompt}
{% endchat %}
{% chat role="user" %}
Context: {{ context_str }}
User Query: {{ query_str }}
{% endchat %}
  • Notes:
    • Custom templates must be writting in Jinja syntax format (see above example).
    • {system_prompt} is where LanguageModelContext value will be injected.
    • {format_prompt} is where FormatPrompt value will be injected.
    • Refer to Llama Index Rich Prompt Template for prompt layout.
Supported LLM providers:
  • Google Cloud Platform (GCP)
  • Amazon Web Services (AWS)
  • Azure OpenAI (AzureOpenAI)
  • Hugging Face (HuggingFace)
  • Sage Maker (SageMaker)
  • More coming soon...
Embedding models:

Here are some embedding models that have been tested with the app:

ModelEmbedding Dimensions
BAAI/bge-small-en-v1.5384
nomic-ai/nomic-embed-text-v1.5768
nomic-ai/nomic-embed-text-v2-moe768

Notes:

  • Only Hugging Face and AzureOpenAI Embedding models are supported at the moment.
  • For standard RAG mode document chunking overlap is a minimum of 50 words OR 10% if higher than 50 words.
Tests
  • Standard tests

    • Standard Talk to Docs tests will automatically run during the application start-up process. This consists of 141 assertion tests.
  • Cloud integration tests

    • Cloud integration tests will run when RUN_INTEGRATION_TESTS = true. These tests cover document storage downloads and uploads, as well as LLM and Embedding models requests and responses.
  • End-to-end tests

    • End-to-end tests will run when RUN_E2E_TESTS = true and after the full application initialization process is complete. These test cover the entire talk-to-docs flow and will pass if a proper final response is recieved via a Direct Line request.
Other Envs:
Environment VariableDescription
connections__serviceConnection__settings__clientIdAzure Application ID for Microsoft Teams bot authentication
connections__serviceConnection__settings__clientSecretAzure Application secret for Microsoft Teams bot authentication - Remove this env for UserAssignedMSI
connections__serviceConnection__settings__tenantIdAzure Active Directory Tenant ID for the bot
connectionsMap__0__connectionConnection name for the application (default: serviceConnection)
connectionsMap__0__serviceUrlURL of the application connection (default: *)
TalkToDocsControls bot mode; "true" = Talk-to-Docs only, "false" = NLSQL only, "" = both (NLSQL with Talk-to-Docs fallback)
DEVWhen true launches the app in development mode for using local Azurite Blob storage
AZURE_STORAGE_CONNECTION_STRINGConnection string for connecting to local Azurite storage (development mode)
DEBUGEnable verbose debug logging; Options: true, false (default: false)

Tag summary

Content type

Image

Digest

sha256:b58dcaa3c

Size

1.2 GB

Last updated

7 months ago

docker pull denissa4/aiagent-master