Add organizations, semantic search, and user personas

✅ merged · #1 · Chris-o-O/mike-explor ← Chris-o-O/mike-explor · opened 19d ago by Chris-o-O · merged 19d ago by Chris-o-O · self · +2,345-30 across 33 files · ↗ on GitHub

From the PR description

Summary

This PR introduces three major features to the platform:

  1. Organizations & Team Management - Users can now create organizations, invite team members by email, and manage org-level settings (jurisdictions, practice areas, custom instructions, language).

  2. Semantic Search - Documents are now indexed using Voyage AI's legal-optimized embeddings (voyage-law-2), enabling semantic similarity search across document chunks with page number tracking.

  3. User Personas - Extended user profiles to capture professional context (role, practice areas, bar number, custom instructions) and organization membership, which enriches LLM system prompts.

Key Changes

Backend

  • New routes:

    • POST/GET/PATCH /organizations - Create, retrieve, and update organizations
    • GET /organizations/:id/members - List org members with enriched profile data
    • POST/GET/DELETE /organizations/:id/invites - Manage email-based invitations (7-day expiry)
    • POST /organizations/:id/join - Accept pending invitations
    • POST /search/semantic - Semantic search across documents using embeddings
    • GET/PATCH /user/persona - Fetch and update user persona fields
  • New libraries:

    • lib/embeddings.ts - Text chunking (800 chars, 150 overlap), Voyage AI API integration, vector persistence
    • lib/persona.ts - Fetch and build persona context from user + org data
    • lib/llm/openrouter.ts - OpenRouter API client with streaming and tool support
  • Database migrations:

    • 001_add_openrouter_voyage.sql - pgvector extension, document_chunks table with 1024-dim embeddings, cosine similarity RPC
    • 002_personas.sql - organizations, organization_members, organization_invites tables; extended user_profiles with persona fields
  • Tool additions:

    • Added semantic_search tool to chat tools for LLM-driven document search

Frontend

  • New pages:

    • account/company/page.tsx - Full org management UI (create, edit, invite, member list, leave)
    • account/page.tsx - Extended with persona fields (role, practice areas, bar number, custom instructions)
  • New components:

    • SemanticSearchWidget.tsx - Debounced search UI with result display and click handlers
  • API client updates:

    • Added organization, invite, and persona endpoints to mikeApi.ts
    • Added semantic search endpoint
  • Context & utilities:

    • Extended UserProfileContext with persona fields and openrouter API key
    • Updated modelAvailability.ts to support OpenRouter as a provider
    • Updated ModelToggle.tsx to include OpenRouter models
  • UI components:

    • Added Textarea component for multi-line inputs

Integration Points

  • Chat and project chat routes now fetch and inject persona context into system prompts
  • Document upload flow triggers semantic indexing via indexDocumentVersion()
  • Model selection now includes OpenRouter models alongside Claude and Gemini
  • Project page includes semantic search widget for document discovery

Notable Implementation Details

  • Organization invites use email-based upsert with 7-day expiry
  • Slugs are auto-generated with random suffix to ensure uniqueness
  • Document chunks preserve page numbers from PDF [Page N] markers
  • Persona context is hierarchical: user settings override org defaults in prompts
  • Semantic search supports filtering by document IDs and configurable result count (top_k)
  • OpenRouter client uses OpenAI SDK with custom base URL for compatibility

https://claude.ai/code/session_01NJxa5NasJ9qhaMkzEyqr2u

Our analysis

OpenRouter multi-model + Voyage AI semantic search — read the full analysis →

OpenRouter multi-model + Voyage AI semantic search — read the full analysis →

Think the analysis missed something the PR description covers?

Commits in this PR (4)

SHA Subject Author Date
3279a584 Add OpenRouter multi-model support and Voyage AI semantic search Claude 2026-05-07 ↗ GitHub
commit body
OpenRouter: extends the LLM provider abstraction to support GPT-4o,
GPT-4 Turbo, Mistral Large, Llama 3.3 70B, and Gemma 3 27B via a
single OpenRouter API key. Follows the same provider pattern as Claude
and Gemini - new openrouter.ts adapter, model routing by prefix, per-user
API key stored in user_profiles, and full UI integration (model toggle,
availability checks, account settings key field).

Semantic search: adds Voyage AI embeddings (voyage-law-2, optimised for
legal documents) to index document chunks at upload time (fire-and-forget,
controlled by VOYAGE_API_KEY env var). Chunks are stored in a new
document_chunks pgvector table. A /search/semantic endpoint and a
semantic_search LLM tool enable concept-level retrieval. A new
SemanticSearchWidget in ProjectPage exposes document search by meaning.

https://claude.ai/code/session_01NJxa5NasJ9qhaMkzEyqr2u
3279a584 Add OpenRouter multi-model support and Voyage AI semantic search Claude 2026-05-07 ↗ GitHub
commit body
OpenRouter: extends the LLM provider abstraction to support GPT-4o,
GPT-4 Turbo, Mistral Large, Llama 3.3 70B, and Gemma 3 27B via a
single OpenRouter API key. Follows the same provider pattern as Claude
and Gemini - new openrouter.ts adapter, model routing by prefix, per-user
API key stored in user_profiles, and full UI integration (model toggle,
availability checks, account settings key field).

Semantic search: adds Voyage AI embeddings (voyage-law-2, optimised for
legal documents) to index document chunks at upload time (fire-and-forget,
controlled by VOYAGE_API_KEY env var). Chunks are stored in a new
document_chunks pgvector table. A /search/semantic endpoint and a
semantic_search LLM tool enable concept-level retrieval. A new
SemanticSearchWidget in ProjectPage exposes document search by meaning.

https://claude.ai/code/session_01NJxa5NasJ9qhaMkzEyqr2u
4f16dc2b feat: personas, company/team management, organisation context injection Claude 2026-05-08 ↗ GitHub
commit body
- Company & Team tab: create/join/edit orgs, manage members and invites, admin roles
- My Profile section in General tab: role, practice areas, bar number, personal AI instructions
- DB: organizations, organization_members, organization_invites tables + user_profiles persona columns
- Persona context injected into every chat and project chat system prompt
- REST API: /organizations/* CRUD + /user/persona GET/PATCH
- Textarea UI component

https://claude.ai/code/session_01NJxa5NasJ9qhaMkzEyqr2u
4f16dc2b feat: personas, company/team management, organisation context injection Claude 2026-05-08 ↗ GitHub
commit body
- Company & Team tab: create/join/edit orgs, manage members and invites, admin roles
- My Profile section in General tab: role, practice areas, bar number, personal AI instructions
- DB: organizations, organization_members, organization_invites tables + user_profiles persona columns
- Persona context injected into every chat and project chat system prompt
- REST API: /organizations/* CRUD + /user/persona GET/PATCH
- Textarea UI component

https://claude.ai/code/session_01NJxa5NasJ9qhaMkzEyqr2u

Capture this PR into my fork

Download a Markdown prompt that tells Claude how to port every commit in this PR into your working tree. Run it via claude -p < capture-pull-1.md from inside the repo you want the changes in.

⬇ Download capture-pull-1.md