Skip to content

Added memory_search and Merged knowledge_extract and memory_operation#15

Merged
ngduyanhece merged 10 commits intomainfrom
feat/memory-operation-tool
Jul 6, 2025
Merged

Added memory_search and Merged knowledge_extract and memory_operation#15
ngduyanhece merged 10 commits intomainfrom
feat/memory-operation-tool

Conversation

@RyanNg1403
Copy link
Copy Markdown
Collaborator


🧠 Memory System Refactor: Unified Operations & Search

📋 Overview

Major refactor consolidating memory extraction and operations into a single atomic tool while adding semantic search capabilities for improved knowledge management.

🔄 Key Changes

1. Merged extract_knowledge + memory_operationcipher_extract_and_operate_memory

Benefits:

  • Efficient Operations: Single step extraction and memory management
  • Smart Filtering: Automatically excludes non-technical content

2. Added cipher_memory_search for Knowledge Retrieval

Features:

  • 🔍 Semantic Search: Vector-based similarity matching
  • 🎯 Configurable: Query, top_k (1-50), similarity_threshold (0.0-1.0), type filtering
  • 📊 Rich Results: Detailed metadata and similarity scores
  • 🚀 Performance Optimized: Efficient vector search with threshold filtering

🔧 Updated Workflow

  1. User Input → Agent processes message and tools (including cipher_memory_search)
  2. Response Generation → Agent generates response using available context
  3. Automatic Memory Managementcipher_extract_and_operate_memory extracts and persists knowledge

📈 Improvements

  • Searchability: Semantic retrieval of relevant past knowledge
  • Enhanced Prompts: Improved filtering to extract important programming content only
  • Non-Blocking: cipher_extract_and_operate_memory runs automatically after each interaction without blocking agent responses

Note: When running in CLI, the agent response is displayed at last (after cipher_extract_and_operate_memory is done, however, the response is already generated before this tool call. This is done because I want the response to be at the end of each interaction, without any tool usage log showing up after that. The display order can be easily switched as follows.

File: src/core/session/coversation-session.ts (lines ~60-65)

// Generate response
const response = await this.llmService.generate(input, imageDataInput, stream);

// PROGRAMMATIC ENFORCEMENT: Memory extraction runs in background (non-blocking)
this.enforceMemoryExtraction(input, response).catch(error => {
    logger.error('ConversationSession: Background memory extraction failed', { error });
});

return response; // CLI displays response IMMEDIATELY, memory extraction logs appear after

🛠️ Technical Details

  • Consolidated Logic: Single tool handles extraction + operation
  • Shared Utilities: Reuses functions from memory_operation.ts
  • Error Handling: Graceful fallbacks and comprehensive logging
  • Backward Compatibility: Deprecated tools preserved for reference

📋 Migration

  • New Tools: Use cipher_extract_and_operate_memory and cipher_memory_search
  • Deprecated: extract_knowledge and memory_operation (commented out)
  • Config: SEARCH_MEMORY_TYPE environment variable controls search defaults

@ngduyanhece
Copy link
Copy Markdown
Contributor

@RyanNg1403
Screenshot 2025-07-06 at 17 12 09
got the test case failed! please kindly check

@RyanNg1403 RyanNg1403 mentioned this pull request Jul 6, 2025
@ngduyanhece ngduyanhece merged commit a1aa3a6 into main Jul 6, 2025
@ngduyanhece ngduyanhece deleted the feat/memory-operation-tool branch July 6, 2025 14:36
Ptah-CT pushed a commit to DerAuctor/ct-cipher that referenced this pull request Oct 2, 2025
Ptah-CT pushed a commit to DerAuctor/ct-cipher that referenced this pull request Oct 2, 2025
…n-tool

Added memory_search and Merged knowledge_extract and memory_operation
hieuntg81 added a commit that referenced this pull request Apr 22, 2026
…iew #15)

The sweep loop that evicts expired entries used to run only inside
set(). Long-running daemons that are read-heavy (cache once, sign
many) therefore never reclaimed memory for keys the user had stopped
using — get() only deleted the single entry it happened to touch.

Extract `sweep(now)` as a private method and call it from both get()
and set(). Ceiling growth was already practically bounded
(projects × keys × ~1KB) so this is mostly a code-smell / symmetry
fix rather than a memory leak.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants