Repository navigation
Phase 5 retrieval - #5
Merged
Merged
Conversation
Resolved issues are embedded locally (fastembed, bge-small-en-v1.5) and stored with pgvector in the application's PostgreSQL, in an `ai` schema owned by a restricted ai_service role that has no access to the public schema. - ai-db bootstrap creates the role, schema and extension (idempotent); ai-db migrate applies Alembic migrations as ai_service. - Endpoints to index and remove documents, find similar issues, and suggest a resolution. Every query is scoped to company_id in SQL and can be narrowed to the products the viewer may open. - The title and description are embedded; staff resolution notes are stored for suggestions but not embedded. - Suggested resolutions may only cite retrieved tickets and must be consistent; past issues are wrapped in delimiters like client text. No LLM call is made when nothing clears the similarity threshold. - Retrieval degrades to 503 RETRIEVAL_UNAVAILABLE if its database or model can't start; triage and sentiment are unaffected. - ai-serve runs uvicorn on a selector event loop, which psycopg's async mode needs on Windows. Connections have a 10s connect timeout. - Shared LLM call validation (llm_call.py) for every feature. - 75 new tests: one contract for the in-memory and Postgres stores, database-enforced isolation, citation checks and injection handling.
A developer's local .env filled in variables that tests deliberately removed, so the AI_SERVICE_TOKEN startup check passed or failed depending on the machine. Tests now never read .env.
- index_issue jobs keep the similarity index in step with resolved issues: queued on resolve, reopen, edit while resolved and staff comments while resolved, at most one at a time. The worker reads the current state and indexes (staff notes as resolution) or removes. - GET /issues/:id/ai/similar and POST/GET /issues/:id/ai/resolution, scoped to the issue's company and the products the viewer can open. Every result is re-checked against the viewer's tenancy, which also drops issues reopened or deleted since indexing. - Suggested resolutions are stored with model, prompt version and sources; helpful/not-helpful feedback is recorded once. Call cost is logged, including for failed generations. - npm run ai:reindex rebuilds the index and removes deleted issues. - 17 new tests, including a post-filter test where the AI service returns issues from another company, another product, a reopened issue and a deleted one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a comprehensive retrieval system to the AI service, enabling similar-issue search and suggested resolutions grounded in past issues. It adds vector search capabilities using PostgreSQL with the pgvector extension, local embeddings via fastembed, and a robust tenant isolation model. The documentation, configuration, and testing infrastructure have all been significantly updated to reflect and support these new features.
Retrieval and Vector Search System
ai-service/README.md[1] [2] [3];ai-service/.env.example[4]Database and Migrations
aischema, including the creation of theissue_documentstable with appropriate indexes and constraints for company and product isolation. Alembic configuration and migration scripts are provided. (ai-service/alembic.ini[1]ai-service/migrations/env.py[2]ai-service/migrations/versions/0001_issue_documents.py[3]ai-service/migrations/script.py.mako[4]Configuration and Dependencies
.envto support retrieval configuration, embedding provider/model, and connection details for the vector database. Added new dependencies for Alembic, fastembed, pgvector, and psycopg. (ai-service/.env.example[1]ai-service/pyproject.toml[2] [3]API and Dependency Injection
ai-service/src/ai_service/api/deps.py[1] [2]Documentation and Testing
ai-service/README.md[1] [2] [3] [4] [5] [6] [7] [8] [9];ai-service/pyproject.toml[10]These changes collectively enable robust, secure, and efficient retrieval-based AI assistance in the service.