mirror of
https://github.com/mtayfur/openwebui-memory-system.git
synced 2026-01-22 06:51:01 +01:00
add current model usecase
This commit is contained in:
@@ -8,7 +8,6 @@ import hashlib
|
||||
import json
|
||||
import logging
|
||||
import statistics
|
||||
import statistics
|
||||
import time
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime, timezone
|
||||
@@ -28,7 +27,6 @@ from open_webui.models.users import Users
|
||||
from open_webui.routers.memories import Memories
|
||||
from fastapi import Request
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_SHARED_SKIP_DETECTOR_CACHE = {}
|
||||
@@ -49,8 +47,6 @@ class Constants:
|
||||
# Cache System
|
||||
MAX_CACHE_ENTRIES_PER_TYPE = 500 # Maximum cache entries per cache type
|
||||
MAX_CONCURRENT_USER_CACHES = 50 # Maximum concurrent user cache instances
|
||||
MAX_CACHE_ENTRIES_PER_TYPE = 500 # Maximum cache entries per cache type
|
||||
MAX_CONCURRENT_USER_CACHES = 50 # Maximum concurrent user cache instances
|
||||
CACHE_KEY_HASH_PREFIX_LENGTH = 10 # Hash prefix length for cache keys
|
||||
|
||||
# Retrieval & Similarity
|
||||
@@ -108,7 +104,6 @@ Build precise memories of the user's personal narrative with factual, temporal s
|
||||
- Ensure Memory Quality:
|
||||
- High Bar for Creation: Only CREATE memories for significant life facts, relationships, events, or core personal attributes. Skip trivial details or passing interests.
|
||||
- Contextual Completeness: Combine related information into cohesive statements. Group connected facts (same topic, person, event, or timeframe) into single memories rather than fragmenting. Include supporting details while respecting boundaries. Only combine directly related facts. Avoid bare statements and never merge unrelated information.
|
||||
- Contextual Completeness: Combine related information into cohesive statements. Group connected facts (same topic, person, event, or timeframe) into single memories rather than fragmenting. Include supporting details while respecting boundaries. Only combine directly related facts. Avoid bare statements and never merge unrelated information.
|
||||
- Mandatory Semantic Enhancement: Enhance entities with descriptive categorical nouns for better retrieval.
|
||||
- Verify Nouns/Pronouns: Link pronouns (he, she, they) and nouns to specific entities.
|
||||
- First-Person Format: Write all memories in English from the user's perspective.
|
||||
@@ -493,8 +488,6 @@ class SkipDetector:
|
||||
def _initialize_reference_embeddings(self) -> None:
|
||||
"""Compute and cache embeddings for category descriptions."""
|
||||
try:
|
||||
technical_embeddings = self.embedding_function(
|
||||
self.TECHNICAL_CATEGORY_DESCRIPTIONS
|
||||
technical_embeddings = self.embedding_function(
|
||||
self.TECHNICAL_CATEGORY_DESCRIPTIONS
|
||||
)
|
||||
@@ -869,7 +862,6 @@ CANDIDATE MEMORIES:
|
||||
|
||||
selected_memories = []
|
||||
for memory in candidate_memories:
|
||||
if memory["id"] in response.ids and len(selected_memories) < max_count:
|
||||
if memory["id"] in response.ids and len(selected_memories) < max_count:
|
||||
selected_memories.append(memory)
|
||||
|
||||
@@ -1260,7 +1252,6 @@ class LLMConsolidationService:
|
||||
)
|
||||
logger.info(f"🔄 Memory Operations: {', '.join(operation_details)}")
|
||||
await self.memory_system._refresh_user_cache(user_id)
|
||||
await self.memory_system._refresh_user_cache(user_id)
|
||||
|
||||
return created_count, updated_count, deleted_count, failed_count
|
||||
|
||||
@@ -1386,8 +1377,6 @@ class Filter:
|
||||
self._background_tasks: set = set()
|
||||
self._shutdown_event = asyncio.Event()
|
||||
|
||||
self._embedding_function = None
|
||||
self._skip_detector = None
|
||||
self._embedding_function = None
|
||||
self._skip_detector = None
|
||||
|
||||
@@ -1519,10 +1508,6 @@ class Filter:
|
||||
self, embedding: Union[List[float], np.ndarray]
|
||||
) -> np.ndarray:
|
||||
"""Normalize embedding vector."""
|
||||
if isinstance(embedding, list):
|
||||
embedding = np.array(embedding, dtype=np.float16)
|
||||
else:
|
||||
embedding = embedding.astype(np.float16)
|
||||
if isinstance(embedding, list):
|
||||
embedding = np.array(embedding, dtype=np.float16)
|
||||
else:
|
||||
@@ -1689,7 +1674,6 @@ class Filter:
|
||||
top_score = max(scores)
|
||||
lowest_score = min(scores)
|
||||
median_score = statistics.median(scores)
|
||||
median_score = statistics.median(scores)
|
||||
|
||||
context_label = (
|
||||
"📊 Consolidation candidate memories"
|
||||
@@ -2095,8 +2079,6 @@ class Filter:
|
||||
|
||||
await self._cache_manager.clear_all_caches()
|
||||
|
||||
async def _refresh_user_cache(self, user_id: str) -> None:
|
||||
"""Refresh user cache - clear stale caches and update with fresh embeddings."""
|
||||
async def _refresh_user_cache(self, user_id: str) -> None:
|
||||
"""Refresh user cache - clear stale caches and update with fresh embeddings."""
|
||||
start_time = time.time()
|
||||
@@ -2155,8 +2137,6 @@ class Filter:
|
||||
"""Execute a single memory operation."""
|
||||
try:
|
||||
if operation.operation == Models.MemoryOperationType.CREATE:
|
||||
content_stripped = operation.content.strip()
|
||||
if not content_stripped:
|
||||
content_stripped = operation.content.strip()
|
||||
if not content_stripped:
|
||||
logger.warning(f"⚠️ Skipping CREATE operation: empty content")
|
||||
@@ -2171,8 +2151,6 @@ class Filter:
|
||||
return Models.MemoryOperationType.CREATE.value
|
||||
|
||||
elif operation.operation == Models.MemoryOperationType.UPDATE:
|
||||
id_stripped = operation.id.strip()
|
||||
if not id_stripped:
|
||||
id_stripped = operation.id.strip()
|
||||
if not id_stripped:
|
||||
logger.warning(f"⚠️ Skipping UPDATE operation: empty ID")
|
||||
@@ -2197,8 +2175,6 @@ class Filter:
|
||||
return Models.MemoryOperationType.UPDATE.value
|
||||
|
||||
elif operation.operation == Models.MemoryOperationType.DELETE:
|
||||
id_stripped = operation.id.strip()
|
||||
if not id_stripped:
|
||||
id_stripped = operation.id.strip()
|
||||
if not id_stripped:
|
||||
logger.warning(f"⚠️ Skipping DELETE operation: empty ID")
|
||||
|
||||
Reference in New Issue
Block a user