ragka-v1-codex
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.3%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: guiiids
- Language: Python
- Default Branch: main
- Size: 5.34 MB
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Enhanced Memory Management for RAG Assistant
This project implements an enhanced memory management solution for the RAG (Retrieval-Augmented Generation) assistant with conversation history. The solution addresses the problem of context overflow by implementing smart context summarization that preserves critical information.
Problem
In conversational AI systems with memory, as the conversation grows longer, the context window becomes full. Traditional approaches simply truncate older messages, which can lead to:
- Loss of important product information mentioned earlier
- Loss of citation references
- Inconsistent responses due to missing context
- Degraded user experience
Solution
The enhanced memory management solution uses smart context summarization to:
- Preserve key information from older messages
- Maintain all citation references in their original form
- Keep product-specific information intact
- Reduce token usage while maintaining conversation coherence
Implementation
The implementation consists of the following components:
- Summarization Settings: Configuration options to control the summarization behavior
- Summarization Method: A method that summarizes older messages while preserving key information
- Enhanced Trim History: A modified history trimming method that uses summarization instead of simple truncation
- Settings Integration: Integration with the existing settings system
Usage
Basic Usage
The enhanced memory management is enabled by default. To use it, simply initialize the RAG assistant as usual:
```python from ragassistantv2 import FlaskRAGAssistant
Initialize with default settings (summarization enabled)
rag_assistant = FlaskRAGAssistant()
Use the RAG assistant as usual
answer, citedsources, _, _, _ = ragassistant.generateragresponse("What are the key features of the Agilent 1290 Infinity II LC System?") ```
Custom Configuration
You can customize the summarization behavior through settings:
python
rag_assistant = FlaskRAGAssistant(settings={
"max_history_turns": 5, # Number of conversation turns to keep without summarization
"summarization_settings": {
"enabled": True, # Whether to use summarization (vs. simple truncation)
"max_summary_tokens": 800, # Maximum length of summaries
"summary_temperature": 0.3 # Temperature for summary generation
}
})
Disabling Summarization
If you prefer the original truncation behavior, you can disable summarization:
python
rag_assistant = FlaskRAGAssistant(settings={
"summarization_settings": {
"enabled": False # Fall back to simple truncation
}
})
Testing
A test script is provided to demonstrate the functionality:
bash
python test_smart_memory.py
This script simulates a conversation with multiple turns and shows how the summarization is triggered when the history exceeds the configured limit.
Benefits
- Improved Context Preservation: Critical information from earlier in the conversation is preserved
- Citation Integrity: All citation references are maintained for proper attribution
- Product Information Retention: Specific product details mentioned earlier remain available
- Token Efficiency: Reduces token usage while maintaining conversation coherence
- Better User Experience: Provides more consistent responses by preserving important context
Limitations
- Additional API Call: Summarization requires an additional API call, which may increase latency
- Summary Quality: The quality of the summary depends on the LLM's summarization capabilities
- Trade-offs: There's a balance between summary length and information preservation
Files
rag_assistant_v2.py: The enhanced RAG assistant with smart context summarizationtest_smart_memory.py: A test script that demonstrates the functionalityimplementation_example.py: An example of how to integrate the solution into your codebaseenhanced_memory_implementation_plan.md: Detailed implementation plan with code snippetsREADME.md: This file, providing an overview of the solution
Future Improvements
- Adaptive Summarization: Adjust summarization parameters based on conversation characteristics
- Selective Summarization: Only summarize parts of the conversation that are less relevant
- Multi-level Summarization: Use multiple levels of summarization for very long conversations
- Evaluation Metrics: Add metrics to evaluate the quality of summaries
Owner
- Login: guiiids
- Kind: user
- Repositories: 1
- Profile: https://github.com/guiiids
Citation (citation_diagnostic.py)
import logging
import os
from rag_assistant_v2 import FlaskRAGAssistantV2, get_phase_logger
# Setup detailed logging to capture the new debug output
log_level_str = os.environ.get("LOG_LEVEL", "INFO").upper()
log_level = getattr(logging, log_level_str, logging.INFO)
# Get the logger and set its level
logger = get_phase_logger(3)
logger.setLevel(log_level)
# Also, ensure the handlers have the correct level
for handler in logging.getLogger('rag_improvement').handlers:
handler.setLevel(log_level)
logger.info("--- Starting Citation Diagnostic ---")
def run_diagnostic():
"""
Runs a diagnostic test to debug the citation repetition issue.
"""
try:
# 1. Instantiate the RAG assistant
# We can pass an empty settings dict as we will manually set up the state.
assistant = FlaskRAGAssistantV2(settings={})
logger.info("RAG Assistant instantiated.")
# 2. Define a query that triggers the issue
query = "What is the difference between CrossLab Connect and iLab?"
logger.info(f"Test Query: {query}")
# 3. Simulate the internal state that leads to the problem.
# This involves manually setting the _cumulative_src_map and other
# relevant attributes to mimic a multi-turn conversation.
# Simulate sources from a previous turn (some with same title)
assistant._cumulative_src_map = {
'S_1721728802738_d8e8f33f': {'title': 'iLab Community_2312958.pdf', 'content': 'Content about iLab Community.', 'parent_id': 'doc1', 'is_procedural': False},
'S_1721728802739_a1b2c3d4': {'title': 'Key iLab Terms_261285.pdf', 'content': 'Content with key iLab terms.', 'parent_id': 'doc2', 'is_procedural': False},
'S_1721728802740_e5f6g7h8': {'title': 'Key iLab Terms_261285.pdf', 'content': 'More content with key iLab terms.', 'parent_id': 'doc2', 'is_procedural': False},
'S_1721728802741_i9j0k1l2': {'title': 'iLab Registration & Login Guide_2287669.pdf', 'content': 'Guide to iLab registration.', 'parent_id': 'doc3', 'is_procedural': False},
'S_1721728802742_m3n4o5p6': {'title': 'iLab Quick-Start Guide_1475196.pdf', 'content': 'Quick start guide for iLab.', 'parent_id': 'doc4', 'is_procedural': False}
}
# Simulate the _display_ordered_citations from a previous turn
assistant._display_ordered_citations = list(assistant._cumulative_src_map.keys())
assistant._display_ordered_citation_map = assistant._cumulative_src_map
logger.info(f"Simulated cumulative source map with {len(assistant._cumulative_src_map)} sources.")
# 4. Simulate the model's response that contains repeated citation numbers
simulated_answer = """
No, CrossLab Connect (CLC) is not the same as iLab. While both are Agilent platforms, they serve different purposes and cater to distinct workflows.
CrossLab Connect:
Purpose: Focuses on streamlining laboratory operations, asset management, service requests, and data monitoring. It integrates tools like MyAgilent for unified access to Agilent services [1], [4], [5].
Features:
Provides graphical insights on dashboards for tracking support requests and assets [4], [5].
Offers enhanced onboarding and authentication processes, including CRM Contact ID and SSO security [4].
Includes tools like Smart Alerts for secure data connections and monitoring [4].
Supports service submissions with features like direct photo capture [5].
Applications: Ideal for labs looking to optimize workflows, manage assets, and improve data security [4], [5].
iLab:
Purpose: Designed for managing core facilities, labs, and workflows, with tools for ordering services, managing funds, and generating reports [4], [4].
Features:
Provides roles like Institutional Administrators, Principal Investigators, and Core Administrators for managing lab memberships and financial approvals [4], [4].
Offers resources like forums, blogs, how-to videos, and a resource library for user support [1].
Hosted on regional servers for optimized performance and compliance with local regulations [4].
Applications: Primarily used for research and administrative workflows in labs and institutions [4], [4].
Key Differences:
Focus: CrossLab Connect emphasizes asset management and service requests, while iLab focuses on workflow and financial management for labs and core facilities.
Integration: CrossLab Connect integrates with MyAgilent for unified access, whereas iLab is hosted on regional servers tailored to institutional needs.
User Base: iLab is used globally by institutions and labs, while CrossLab Connect is more focused on operational and service management.
In summary, CrossLab Connect and iLab are distinct platforms tailored to different aspects of laboratory management and operations [1], [4], [4], [5].
"""
logger.info("Using simulated answer for diagnosis.")
# 5. Call the function under investigation directly
logger.info("Calling _assemble_cited_sources to trigger the new logging...")
cited_sources, renumber_map = assistant._assemble_cited_sources(simulated_answer, assistant._cumulative_src_map)
# 6. Print the results for analysis
print("\n--- DIAGNOSTIC RESULTS ---")
print(f"Number of cited sources returned: {len(cited_sources)}")
print("\nCited Sources (with Display IDs):")
for source in cited_sources:
print(f" Display ID: {source.get('display_id')}, Title: {source.get('title')}, Unique ID: {source.get('id')}")
print("\nRenumber Map:")
for unique_id, display_id in renumber_map.items():
print(f" Unique ID: {unique_id} -> Display ID: {display_id}")
print("\n--- END OF DIAGNOSTIC RESULTS ---\n")
logger.info("--- Citation Diagnostic Finished ---")
except Exception as e:
logger.error(f"An error occurred during the diagnostic: {e}", exc_info=True)
if __name__ == "__main__":
# Set environment variable to see detailed logs
# Example: LOG_LEVEL=DEBUG python citation_diagnostic.py
run_diagnostic()
GitHub Events
Total
- Delete event: 1
- Push event: 12
- Pull request event: 12
- Create event: 6
Last Year
- Delete event: 1
- Push event: 12
- Pull request event: 12
- Create event: 6
Dependencies
- python 3.11-slim build
- guivieiraa/ragka-v1_5 latest
- @types/http-proxy 1.17.16
- @types/node 24.1.0
- accepts 2.0.0
- body-parser 2.2.0
- braces 3.0.3
- bytes 3.1.2
- call-bind-apply-helpers 1.0.2
- call-bound 1.0.4
- content-disposition 1.0.0
- content-type 1.0.5
- cookie 0.7.2
- cookie-signature 1.2.2
- cors 2.8.5
- debug 4.4.1
- depd 2.0.0
- dunder-proto 1.0.1
- ee-first 1.1.1
- encodeurl 2.0.0
- es-define-property 1.0.1
- es-errors 1.3.0
- es-object-atoms 1.1.1
- escape-html 1.0.3
- etag 1.8.1
- eventemitter3 4.0.7
- express 5.1.0
- fill-range 7.1.1
- finalhandler 2.1.0
- follow-redirects 1.15.9
- forwarded 0.2.0
- fresh 2.0.0
- function-bind 1.1.2
- get-intrinsic 1.3.0
- get-proto 1.0.1
- gopd 1.2.0
- has-symbols 1.1.0
- hasown 2.0.2
- http-errors 2.0.0
- http-proxy 1.18.1
- http-proxy-middleware 3.0.5
- iconv-lite 0.6.3
- inherits 2.0.4
- ipaddr.js 1.9.1
- is-extglob 2.1.1
- is-glob 4.0.3
- is-number 7.0.0
- is-plain-object 5.0.0
- is-promise 4.0.0
- math-intrinsics 1.1.0
- media-typer 1.1.0
- merge-descriptors 2.0.0
- micromatch 4.0.8
- mime-db 1.54.0
- mime-types 3.0.1
- ms 2.1.3
- negotiator 1.0.0
- object-assign 4.1.1
- object-inspect 1.13.4
- on-finished 2.4.1
- once 1.4.0
- parseurl 1.3.3
- path-to-regexp 8.2.0
- picomatch 2.3.1
- proxy-addr 2.0.7
- qs 6.14.0
- range-parser 1.2.1
- raw-body 3.0.0
- requires-port 1.0.0
- router 2.2.0
- safe-buffer 5.2.1
- safer-buffer 2.1.2
- send 1.2.0
- serve-static 2.2.0
- setprototypeof 1.2.0
- side-channel 1.1.0
- side-channel-list 1.0.0
- side-channel-map 1.0.1
- side-channel-weakmap 1.0.2
- statuses 2.0.1
- statuses 2.0.2
- to-regex-range 5.0.1
- toidentifier 1.0.1
- type-is 2.0.1
- undici-types 7.8.0
- unpipe 1.0.0
- vary 1.1.2
- wrappy 1.0.2
- cors ^2.8.5
- express ^5.1.0
- http-proxy-middleware ^3.0.5
- Flask ==2.3.3
- Flask-CORS ==4.0.0
- requests ==2.31.0
- APScheduler ==3.10.1
- Flask *
- Flask-Cors ==4.0.0
- GitPython ==3.1.44
- Hypercorn ==0.17.3
- Jinja2 ==3.1.6
- Kivy ==2.3.1
- Kivy-Garden ==0.1.5
- Levenshtein ==0.21.1
- MarkupSafe ==3.0.2
- PyJWT ==2.9.0
- PyPDF2 ==3.0.1
- Pygments ==2.19.1
- Quart *
- RapidFuzz ==3.13.0
- Werkzeug ==3.1.3
- aiofiles ==24.1.0
- aiohappyeyeballs ==2.4.3
- aiohttp ==3.11.1
- aiosignal ==1.3.1
- altair ==5.5.0
- annotated-types ==0.7.0
- anyio ==3.7.1
- attrs ==25.3.0
- azure-ai-textanalytics ==5.3.0
- azure-common ==1.1.28
- azure-core ==1.32.0
- azure-cosmos ==4.9.0
- azure-identity ==1.19.0
- azure-search ==1.0.0b2
- azure-search-documents ==11.5.2
- azure-storage-blob ==12.25.1
- beautifulsoup4 ==4.13.3
- black ==25.1.0
- blinker ==1.9.0
- cachetools ==5.5.2
- certifi ==2025.1.31
- cffi ==1.17.1
- charset-normalizer ==3.4.1
- click ==8.1.8
- colorama ==0.4.6
- cryptography ==43.0.3
- distro ==1.9.0
- docutils ==0.21.2
- et_xmlfile ==2.0.0
- filelock ==3.18.0
- filetype ==1.2.0
- fpdf ==1.7.2
- frozenlist ==1.5.0
- fsspec ==2025.5.1
- fuzzywuzzy ==0.18.0
- git-filter-repo ==2.47.0
- gitdb ==4.0.12
- google-api-core ==2.25.1
- google-auth ==2.40.3
- googleapis-common-protos ==1.70.0
- greenlet ==3.2.3
- gunicorn ==21.2.0
- h11 ==0.14.0
- h2 ==4.2.0
- hpack ==4.1.0
- httpcore ==1.0.6
- httpx ==0.27.2
- hyperframe ==6.1.0
- idna ==3.10
- iniconfig ==2.1.0
- isodate ==0.7.2
- isort ==6.0.1
- itsdangerous ==2.2.0
- jiter ==0.7.1
- jsonschema ==4.23.0
- jsonschema-specifications ==2024.10.1
- llvmlite ==0.44.0
- lxml ==5.3.2
- markdown-it-py ==3.0.0
- markdown2 ==2.5.3
- mdurl ==0.1.2
- more-itertools ==10.7.0
- mpmath ==1.3.0
- msal ==1.31.0
- msal-extensions ==1.2.0
- msrest ==0.7.1
- multidict ==6.1.0
- mypy_extensions ==1.1.0
- narwhals ==1.32.0
- networkx ==3.5
- numba ==0.61.2
- numpy ==2.2.4
- oauthlib ==3.2.2
- openai ==1.73.0
- openai-whisper ==20240930
- opencensus ==0.11.4
- opencensus-context ==0.1.3
- opencensus-ext-azure ==1.1.15
- opencensus-ext-flask ==0.8.2
- opencensus-ext-requests ==0.8.0
- openpyxl ==3.1.5
- packaging ==24.2
- pandas ==2.2.3
- pandas-stubs ==2.2.3.241009
- pathlib ==1.0.1
- pathspec ==0.12.1
- pdf2image ==1.17.0
- pillow ==11.1.0
- platformdirs ==4.3.7
- playwright ==1.52.0
- pluggy ==1.5.0
- portalocker ==2.10.1
- priority ==2.0.0
- propcache ==0.2.0
- proto-plus ==1.26.1
- protobuf ==5.29.4
- psutil ==7.0.0
- psycopg2 ==2.9.10
- psycopg2-binary ==2.9.10
- pyarrow ==19.0.1
- pyasn1 ==0.6.1
- pyasn1_modules ==0.4.2
- pycparser ==2.22
- pydantic ==2.9.2
- pydantic-settings ==2.9.1
- pydantic_core ==2.23.4
- pydeck ==0.9.1
- pyee ==13.0.0
- pyobjc-core ==11.0
- pyobjc-framework-Cocoa ==11.0
- pytest ==8.3.5
- python-Levenshtein ==0.21.1
- python-dateutil ==2.9.0.post0
- python-docx ==1.1.2
- python-dotenv ==1.0.0
- python-json-logger ==2.0.7
- pytz ==2025.2
- redis *
- referencing ==0.36.2
- regex ==2024.11.6
- requests ==2.32.3
- requests-oauthlib ==2.0.0
- rich ==13.9.4
- rpds-py ==0.24.0
- rsa ==4.9.1
- rumps ==0.4.0
- six ==1.17.0
- smmap ==5.0.2
- sniffio ==1.3.1
- soupsieve ==2.6
- streamlit ==1.44.0
- streamlit-feedback ==0.1.3
- sympy ==1.14.0
- tenacity ==9.0.0
- tiktoken ==0.9.0
- toml ==0.10.2
- torch ==2.7.1
- tornado ==6.4.2
- tqdm ==4.67.0
- types-pytz ==2024.2.0.20241003
- typing-inspection ==0.4.1
- typing_extensions ==4.13.0
- tzdata ==2025.2
- tzlocal ==5.3.1
- urllib3 ==2.3.0
- watchdog ==6.0.0
- wrapt ==1.17.2
- wsproto ==1.2.0
- yarl ==1.17.1