Skip to content
mentoor

Private AI for sensitive documents

For engineers

Scenario lesson and practice set combining Running models locally, Workplace confidentiality, Vector search and Confidentiality and privilege. Completing it counts as evidence for every listed skill.

The one-sentence idea: when a team wants AI to work on confidential documents, decide first what the documents are and who allows what, then choose a setup where the text stays inside the firm, and enforce access in the database, not in the prompt.

The case

Hartley & Voss is a 14-lawyer firm. Its lawyers lose hours searching old leases, NDAs and call notes. An engineer is asked to build an assistant that finds the right clause and summarizes it. Last week an associate pasted a client's lease into a personal chatbot account to get a quick summary. It worked well, and that is the problem: the quickest route is also the one the firm cannot see, audit or delete from.

The firm's engagement letters promise confidentiality. One matter is under a court seal. An NDA with a counterparty says confidential information must stay on systems the firm controls. These facts, not the technology, set the design.

Why it matters

Four skills meet in this one project. If any of them is missing, the others do not rescue the result.

  • Workplace confidentiality tells you what the material is and whether a tool may touch it.
  • Confidentiality and privilege covers the tool tier, settings, consent and what to do after a slip.
  • Running models locally lets the text stay on a machine the firm owns.
  • Vector search makes the documents findable, and it holds the permission boundary between matters.

How to do it

  1. Sort the documents. List folders and ask what each holds, which contract or seal applies and who owns it. Client matters, NDA material and sealed files go on the strictest list. The firm's blank templates can go anywhere the firm allows.
  2. Pick the tool tier. A free or personal chatbot account has no firm contract, no admin controls and may train on chats. A business plan has a signed agreement and settings an admin can lock. A model running on the firm's own server sends nothing to a third party. For sealed and NDA matters, use the third.
  3. Run the model locally. Install a runner such as Ollama or llama.cpp, pull an open-weight model and set a context size big enough for the documents. Keep the API on 127.0.0.1 and put an authenticated proxy in front of the chat UI. Read the load log: check GPU offload, context length and that the bind address is not 0.0.0.0.
  4. Index with pgvector. Store chunks and their vectors in the firm's existing Postgres, with a matter_id column. Use the distance operator that matches the embedding model, for example <=> with vector_cosine_ops. Take the allowed matter ids from the signed-in user's record on the server. Row-level security is a second lock.
  5. Handle filters honestly. A filter on an approximate index can return fewer rows than asked for. Test a user who sits on one small matter, and use iterative scans, a larger ef_search, partial indexes or partitions.
  6. Control logs and consent. Prompts and answers are client records and may be ordered produced in a dispute. Set a retention period, limit who reads the logs and redact where you can. Where text must go to a hosted provider, get informed client consent that names the data and the provider.
  7. Plan for slips. Tell staff to report a wrong paste the same day. The partner decides whether the client must be told, so speed matters more than tidiness.

Before and after

Before: associates paste files into personal accounts, one shared vector table serves every user, the model API listens on every interface, and the prompt says "only use matter A".

After: sealed and NDA matters use the local model, its API listens on localhost behind sign-in, the search query filters by the matter ids the server looks up, logs have a retention rule, and staff know to report a slip at once.

What goes wrong

  • A prompt used as a lock. The retrieval step has already put other matters' text in the model's context. Enforce access before retrieval.
  • A local model that is open to the network. "Local" means where it runs, not who can call it. Bind it to localhost and authenticate in front of it.
  • Silent truncation. A small context window drops the end of a long contract and the answer still sounds complete. Check the load log and compare answers with the source clause.
  • Redaction that leaves rare facts. A unique detail can identify a client when names are gone.
  • Hidden records. Chat logs and vectors are client data. They need the same retention and access care as the files.

Steps

  1. Sort the folders by contract and seal

    Skill: privacy-workplace

    Before any tool is chosen, list each folder and note what it holds and which duty applies. Client matters, NDA material and sealed files need a tool where text stays under the firm's control. The firm's own templates carry no such limit.

    Document sort for Hartley & Voss
    FolderDutyAllowed tools
    /matters (sealed)Court seal, engagement letterLocal model only
    /matters (other)Engagement letter, NDA termsLocal, or hosted with client consent
    /templatesNoneAny approved tool
  2. Choose the tool tier and settings

    Skill: reg-confidentiality

    Compare options by contract, not by brand. A personal account has no firm contract and may train on chats. A business plan has a signed agreement and admin settings. A local model sends nothing out. Lock training, history and sharing settings for any hosted tool the firm keeps.

    Tool tiers compared
    TierContractWhere text goes
    Personal chatbot accountConsumer termsProvider cloud
    Hosted business planSigned DPA, admin controlsProvider cloud
    Local open-weight modelNone neededFirm server only
  3. Start the local model and read the log

    Skill: local-run

    Install a runner on the firm server, pull the model and set a context size large enough for contracts. Keep the API on localhost and let only an authenticated proxy reach it. Read the load log for three facts: GPU offload, context length and bind address.

    Ollama setup on the firm server

    setup.sh

    ollama pull llama3.1:8b# keep the default bind: 127.0.0.1:11434export OLLAMA_CONTEXT_LENGTH=16384ollama serve
  4. Index chunks in Postgres with a matter column

    Skill: rag-vector-search

    Store chunk text, matter id and embedding in one table. Build an HNSW index with the operator class that matches the embedding model. The search query takes its list of matter ids from the signed-in user's record on the server.

    Search query with matter filter

    search.sql

    SELECT id, bodyFROM chunksWHERE matter_id = ANY($2)ORDER BY embedding <=> $1LIMIT 8;
  5. Test a user on a small matter

    Skill: rag-vector-search

    A selective filter on an approximate index can return fewer rows than asked for. Try a user with one small matter and count the results. If they are short, raise ef_search, enable iterative scans, or add a partial index or partition for that matter.

  6. Set log retention and client consent wording

    Skill: reg-confidentiality

    Prompts and answers are records that can be ordered produced. Decide how long they are kept and who reads them. If any text goes to a hosted provider, the engagement letter says so, names the data shared and tells the client they may object.

  7. Teach the same-day report rule

    Skill: privacy-workplace

    Show staff what the approved route is and what to do after a wrong paste: report it that day to the confidentiality lead, with the tool and the text involved. The partner decides whether the client must be told.

Skills this scenario uses

Where to study