-
Notifications
You must be signed in to change notification settings - Fork 58
LCORE-601: Add RAG chunks in query response #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ef94176
2d798ec
927754c
92d28fe
ffd014f
98f8141
99080a8
0dd1f1d
0d774ce
0871751
930cd74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,8 @@ | |
| DEFAULT_JWT_UID_CLAIM = "user_id" | ||
| DEFAULT_JWT_USER_NAME_CLAIM = "username" | ||
|
|
||
| # default RAG tool value | ||
| DEFAULT_RAG_TOOL = "knowledge_search" | ||
|
Comment on lines
+55
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 🧩 Analysis chainGood centralization; verify no hardcoded tool names remain. Constant name/readability look good. Please confirm there are no remaining string literals "knowledge_search" outside constants. 🏁 Script executed: #!/usr/bin/env bash
# Find stray literals (exclude config/examples)
rg -nP -S "(^|[^A-Za-z0-9_])knowledge_search([^A-Za-z0-9_]|$)" -g '!**/run.yaml' -g '!**/README*' -g '!**/docs/**'Length of output: 148 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
echo "Searching repository for literal 'knowledge_search' using multiple fallbacks..."
# 1) ripgrep (robust flags)
if command -v rg >/dev/null 2>&1; then
echo ":: rg --hidden --no-ignore -uu -F -S"
rg --hidden --no-ignore -uu -F -n "knowledge_search" -S || echo "rg: no matches or search completed"
else
echo "rg not available"
fi
# 2) git grep fallback
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo ":: git grep -n"
git grep -n "knowledge_search" || echo "git grep: no matches"
else
echo "Not a git repo (git grep skipped)"
fi
# 3) find + grep fallback (exclude common heavy dirs)
echo ":: find + grep (excluding .git and node_modules)"
find . -type f -not -path "./.git/*" -not -path "./node_modules/*" -not -path "./dist/*" -print0 \
| xargs -0 grep -nH --line-number -I "knowledge_search" || echo "find+grep: no matches"Length of output: 6544 Replace remaining 'knowledge_search' string literals with DEFAULT_RAG_TOOL Search found literal occurrences in source and tests; update usages to import and use src.constants.DEFAULT_RAG_TOOL (use f"builtin::rag/{DEFAULT_RAG_TOOL}" where the namespaced form is required). Locations:
|
||
|
|
||
| # PostgreSQL connection constants | ||
| # See: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,22 @@ class ModelsResponse(BaseModel): | |||||||||
| ) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class RAGChunk(BaseModel): | ||||||||||
| """Model representing a RAG chunk used in the response.""" | ||||||||||
|
|
||||||||||
| content: str = Field(description="The content of the chunk") | ||||||||||
| source: Optional[str] = Field(None, description="Source document or URL") | ||||||||||
| score: Optional[float] = Field(None, description="Relevance score") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class ToolCall(BaseModel): | ||||||||||
| """Model representing a tool call made during response generation.""" | ||||||||||
|
|
||||||||||
| tool_name: str = Field(description="Name of the tool called") | ||||||||||
| arguments: dict[str, Any] = Field(description="Arguments passed to the tool") | ||||||||||
| result: Optional[dict[str, Any]] = Field(None, description="Result from the tool") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class ReferencedDocument(BaseModel): | ||||||||||
| """Model representing a document referenced in generating a response. | ||||||||||
|
|
||||||||||
|
|
@@ -42,27 +58,27 @@ class ReferencedDocument(BaseModel): | |||||||||
| doc_title: Title of the referenced doc. | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| doc_url: AnyUrl = Field(description="URL of the referenced document") | ||||||||||
| doc_url: Optional[AnyUrl] = Field( | ||||||||||
| None, description="URL of the referenced document" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| doc_title: str = Field(description="Title of the referenced document") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| # TODO(lucasagomes): a lot of fields to add to QueryResponse. For now | ||||||||||
| # we are keeping it simple. The missing fields are: | ||||||||||
| # - truncated: Set to True if conversation history was truncated to be within context window. | ||||||||||
| # - input_tokens: Number of tokens sent to LLM | ||||||||||
| # - output_tokens: Number of tokens received from LLM | ||||||||||
| # - available_quotas: Quota available as measured by all configured quota limiters | ||||||||||
| # - tool_calls: List of tool requests. | ||||||||||
| # - tool_results: List of tool results. | ||||||||||
| # See LLMResponse in ols-service for more details. | ||||||||||
| class QueryResponse(BaseModel): | ||||||||||
| """Model representing LLM response to a query. | ||||||||||
|
|
||||||||||
| Attributes: | ||||||||||
| conversation_id: The optional conversation ID (UUID). | ||||||||||
| response: The response. | ||||||||||
| rag_chunks: List of RAG chunks used to generate the response. | ||||||||||
| referenced_documents: The URLs and titles for the documents used to generate the response. | ||||||||||
| tool_calls: List of tool calls made during response generation. | ||||||||||
| TODO: truncated: Whether conversation history was truncated. | ||||||||||
| TODO: input_tokens: Number of tokens sent to LLM. | ||||||||||
| TODO: output_tokens: Number of tokens received from LLM. | ||||||||||
| TODO: available_quotas: Quota available as measured by all configured quota limiters | ||||||||||
| TODO: tool_results: List of tool results. | ||||||||||
Anxhela21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| """ | ||||||||||
|
|
||||||||||
| conversation_id: Optional[str] = Field( | ||||||||||
|
|
@@ -78,6 +94,13 @@ class QueryResponse(BaseModel): | |||||||||
| ], | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| rag_chunks: list[RAGChunk] = [] | ||||||||||
|
|
||||||||||
|
Comment on lines
+97
to
+98
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix mutable default list in API model. rag_chunks uses [] which is shared across responses; switch to default_factory. - rag_chunks: list[RAGChunk] = []
+ rag_chunks: list[RAGChunk] = Field(
+ default_factory=list, description="List of RAG chunks used to generate the response"
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| tool_calls: Optional[list[ToolCall]] = Field( | ||||||||||
| None, | ||||||||||
| description="List of tool calls made during response generation", | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| referenced_documents: list[ReferencedDocument] = Field( | ||||||||||
| default_factory=list, | ||||||||||
| description="List of documents referenced in generating the response", | ||||||||||
|
|
@@ -99,6 +122,20 @@ class QueryResponse(BaseModel): | |||||||||
| { | ||||||||||
| "conversation_id": "123e4567-e89b-12d3-a456-426614174000", | ||||||||||
| "response": "Operator Lifecycle Manager (OLM) helps users install...", | ||||||||||
| "rag_chunks": [ | ||||||||||
| { | ||||||||||
| "content": "OLM is a component of the Operator Framework toolkit...", | ||||||||||
| "source": "kubernetes-docs/operators.md", | ||||||||||
| "score": 0.95, | ||||||||||
| } | ||||||||||
| ], | ||||||||||
| "tool_calls": [ | ||||||||||
| { | ||||||||||
| "tool_name": "knowledge_search", | ||||||||||
| "arguments": {"query": "operator lifecycle manager"}, | ||||||||||
| "result": {"chunks_found": 5}, | ||||||||||
| } | ||||||||||
| ], | ||||||||||
| "referenced_documents": [ | ||||||||||
| { | ||||||||||
| "doc_url": "https://docs.openshift.com/" | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.