Honcho’s search functionality allows you to find relevant messages and conversations across different scopes - from entire workspaces down to specific peers or sessions.

How Search Works

Search in Honcho is implemented with a two-tier approach:

  1. Primary: PostgreSQL English language full-text search index for intelligent matching
  2. Fallback: Simple string matching for broader coverage

All search results are returned in a paginated format, making it easy to handle large result sets efficiently.

Search Scopes

Search across all content in your workspace - sessions, peers, and messages:

from honcho import Honcho

# Initialize client
honcho = Honcho()

# Search across entire workspace
results = honcho.search("budget planning")

# Iterate through all results
for result in results:
    print(f"Found: {result}")

Search within a specific session’s conversation history:

# Create or get a session
session = honcho.session("team-meeting-jan")

# Search within this session only
results = session.search("action items")

# Process results
for result in results:
    print(f"Session result: {result}")

Search across all content associated with a specific peer:

# Create or get a peer
alice = honcho.peer("alice")

# Search across all of Alice's messages and interactions
results = alice.search("programming")

# View results
for result in results:
    print(f"Alice's content: {result}")

Working with Search Results

Basic Result Processing

# Search returns a paginated iterator
results = honcho.search("customer feedback")

# Simple iteration processes all results automatically
for result in results:
    # Each result contains the matched content and context
    print(f"Match: {result}")
    
# Check if there are any results
results = honcho.search("nonexistent topic")
result_list = list(results)
if not result_list:
    print("No results found")

Manual Pagination

# For manual pagination control, you can work with pages directly
results = honcho.search("project updates")

# The iterator handles pagination automatically, but you can also
# work with individual batches if needed
count = 0
for result in results:
    count += 1
    print(f"Result {count}: {result}")
    
    # Stop after first 10 results
    if count >= 10:
        break

Search with Context Building

# Use search results to build context for LLM interactions
def build_context_from_search(query: str, session_id: str):
    session = honcho.session(session_id)
    
    # Search for relevant past discussions
    search_results = list(session.search(query))
    
    if search_results:
        # Use search results to inform context
        context_summary = f"Found {len(search_results)} relevant past discussions about '{query}'"
        
        # Get normal session context
        session_context = session.get_context(tokens=1500)
        
        return {
            "search_summary": context_summary,
            "session_context": session_context,
            "search_results": search_results[:3]  # Top 3 results
        }
    
    return {"message": "No relevant past discussions found"}

# Build context for a new question
context_data = build_context_from_search("user authentication", "support-session-1")
print(f"Context: {context_data.get('search_summary', 'No context')}")

Best Practices

Handle Empty Results Gracefully

# Always check for empty results
results = honcho.search("very specific query")
result_list = list(results)

if result_list:
    print(f"Found {len(result_list)} results")
    for result in result_list:
        print(f"- {result}")
else:
    print("No results found - try a broader search")

Conclusion

Honcho’s search functionality provides powerful discovery capabilities across your conversational data. By understanding how to:

  • Choose the appropriate search scope (workspace, session, or peer)
  • Handle paginated results effectively
  • Combine search with context building

You can build applications that provide intelligent insights and context-aware responses based on historical conversations and interactions.