-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add rag-embedding and text-embedding functions #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
theothersideofgod
wants to merge
13
commits into
main
Choose a base branch
from
feat/rag-embedding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
25ca320
feat(text-embedding): add text embedding function with Ollama
theothersideofgod 88ed26e
fix: update lockfile for text-embedding generated package
theothersideofgod 2b462b5
feat(rag-embedding): add RAG embedding function with chunking strategies
theothersideofgod 97ba6b6
fix(ci): add SDK utilities and constructive-server port-forward for e…
theothersideofgod 8807a07
fix(fn-runtime): cast graphql-request client types for compatibility
theothersideofgod 9022c8e
feat(rag-embedding): support extractedText field from ProcessFileEmbe…
theothersideofgod e2d725d
feat(text-embedding): implement full pipeline with GraphQL introspection
theothersideofgod 1e50f1a
fix(e2e): use node http module for Host header in GraphQL requests
theothersideofgod 2cab451
test(e2e): add simplified RAG embedding integration test
theothersideofgod 8ff7a43
chore(deps): update lockfile for text-embedding dependencies
theothersideofgod 1b0c250
fix(docker): add pnpm install after generate in Dockerfile.dev
theothersideofgod 235a8be
test(e2e): add text-embedding test for SearchVector embedding flow
theothersideofgod dcd26d7
chore(e2e): remove unstable rag-embedding tests
theothersideofgod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| const mockRequest = jest.fn(); | ||
|
|
||
| jest.mock('graphql-request', () => ({ | ||
| gql: jest.fn((strings: TemplateStringsArray) => strings.join('')), | ||
| })); | ||
|
|
||
| jest.mock('@agentic-kit/ollama', () => { | ||
| return jest.fn().mockImplementation(() => ({ | ||
| generateEmbedding: jest.fn().mockResolvedValue(Array(768).fill(0.1)), | ||
| })); | ||
| }); | ||
|
|
||
| jest.mock('@constructive-io/graphql-query', () => ({ | ||
| SCHEMA_INTROSPECTION_QUERY: 'query { __schema { types { name } } }', | ||
| inferTablesFromIntrospection: jest.fn().mockReturnValue([ | ||
| { | ||
| name: 'article', | ||
| query: { all: 'articles', create: 'createArticle' }, | ||
| inflection: { allRows: 'articles', tableFieldName: 'article' }, | ||
| primaryKey: 'id', | ||
| relations: { belongsTo: [], hasMany: [] }, | ||
| }, | ||
| { | ||
| name: 'article_chunk', | ||
| query: { all: 'articleChunks', create: 'createArticleChunk' }, | ||
| inflection: { allRows: 'articleChunks', tableFieldName: 'articleChunk', createField: 'createArticleChunk' }, | ||
| primaryKey: 'id', | ||
| relations: { | ||
| belongsTo: [{ referencesTable: 'article', fieldName: 'article' }], | ||
| hasMany: [], | ||
| }, | ||
| }, | ||
| ]), | ||
| buildSelect: jest.fn().mockReturnValue({ toString: () => 'query { articles { nodes { id content } } }' }), | ||
| buildPostGraphileCreate: jest.fn().mockReturnValue({ toString: () => 'mutation { createArticleChunk { articleChunk { id } } }' }), | ||
| buildPostGraphileDelete: jest.fn().mockReturnValue({ toString: () => 'mutation { deleteArticleChunks { deletedCount } }' }), | ||
| })); | ||
|
|
||
| const createMockContext = () => ({ | ||
| job: { | ||
| jobId: 'test-job-id', | ||
| workerId: 'test-worker', | ||
| databaseId: 'test-db', | ||
| }, | ||
| client: { | ||
| request: mockRequest, | ||
| }, | ||
| meta: { | ||
| request: jest.fn().mockResolvedValue({ | ||
| schemas: { nodes: [{ schemaName: 'test-db-app-public' }] }, | ||
| }), | ||
| }, | ||
| log: { | ||
| info: jest.fn(), | ||
| error: jest.fn(), | ||
| warn: jest.fn(), | ||
| }, | ||
| env: { | ||
| RAG_EMBEDDING_DRY_RUN: 'true', | ||
| GRAPHQL_URL: 'http://localhost:3000/graphql', | ||
| GRAPHQL_API_NAME: 'private', | ||
| }, | ||
| }); | ||
|
|
||
| const loadHandler = () => { | ||
| const mod = require('../handler'); | ||
| return mod.default ?? mod; | ||
| }; | ||
|
|
||
| describe('rag-embedding handler', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockRequest.mockReset(); | ||
| }); | ||
|
|
||
| it('should return early when content is empty', async () => { | ||
| const handler = loadHandler(); | ||
| const context = createMockContext(); | ||
|
|
||
| mockRequest | ||
| .mockResolvedValueOnce({ __schema: { types: [] } }) // introspection | ||
| .mockResolvedValueOnce({ | ||
| articles: { nodes: [{ id: 'test-id', content: '' }] }, | ||
| }); | ||
|
|
||
| const result = await handler( | ||
| { | ||
| table: 'article', | ||
| schema: 'test-db-app-public', | ||
| id: 'test-id', | ||
| chunks_table: 'article_chunk', | ||
| }, | ||
| context | ||
| ); | ||
|
|
||
| expect(result.complete).toBe(true); | ||
| expect(result.chunks).toBe(0); | ||
| }); | ||
|
|
||
| it('should chunk content and create embeddings', async () => { | ||
| const handler = loadHandler(); | ||
| const context = createMockContext(); | ||
|
|
||
| mockRequest | ||
| .mockResolvedValueOnce({ __schema: { types: [] } }) // introspection | ||
| .mockResolvedValueOnce({ | ||
| articles: { nodes: [{ id: 'test-id', content: 'This is test content for chunking.' }] }, | ||
| }) | ||
| .mockResolvedValueOnce({ deleteArticleChunks: { deletedCount: 0 } }) | ||
| .mockResolvedValueOnce({ | ||
| createArticleChunk: { articleChunk: { id: 'chunk-1' } }, | ||
| }); | ||
|
|
||
| const result = await handler( | ||
| { | ||
| table: 'article', | ||
| schema: 'test-db-app-public', | ||
| id: 'test-id', | ||
| chunks_table: 'article_chunk', | ||
| chunk_size: '1000', | ||
| }, | ||
| context | ||
| ); | ||
|
|
||
| expect(result.complete).toBe(true); | ||
| expect(result.chunks).toBe(1); | ||
| expect(result.chunk_ids).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('should throw error when databaseId is missing', async () => { | ||
| const handler = loadHandler(); | ||
| const context = createMockContext(); | ||
| context.job.databaseId = undefined; | ||
|
|
||
| await expect( | ||
| handler({ table: 'article', schema: 'test-db-app-public', id: 'test-id', chunks_table: 'article_chunk' }, context) | ||
| ).rejects.toThrow('Missing X-Database-Id'); | ||
| }); | ||
|
|
||
| it('should throw error when required params are missing', async () => { | ||
| const handler = loadHandler(); | ||
| const context = createMockContext(); | ||
|
|
||
| await expect( | ||
| handler({ table: '', schema: 'test-db-app-public', id: 'test-id', chunks_table: 'article_chunk' }, context) | ||
| ).rejects.toThrow('Missing required params'); | ||
| }); | ||
|
|
||
| it('should return early when content is empty with trigger format', async () => { | ||
| const handler = loadHandler(); | ||
| const context = createMockContext(); | ||
|
|
||
| mockRequest | ||
| .mockResolvedValueOnce({ __schema: { types: [] } }) // introspection | ||
| .mockResolvedValueOnce({ | ||
| articles: { nodes: [{ id: 'test-id', content: '' }] }, | ||
| }); | ||
|
|
||
| const result = await handler( | ||
| { | ||
| table: 'article', | ||
| schema: 'test-db-app-public', | ||
| id: 'test-id', | ||
| chunks_table: 'article_chunk', | ||
| }, | ||
| context | ||
| ); | ||
|
|
||
| expect(result.complete).toBe(true); | ||
| expect(result.chunks).toBe(0); | ||
| }); | ||
| }); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "name": "rag-embedding", | ||
| "version": "1.0.0", | ||
| "type": "node-graphql", | ||
| "port": 8085, | ||
| "taskIdentifier": "generate_chunks", | ||
| "description": "RAG embedding function - chunks text and generates embeddings using Ollama nomic-embed-text", | ||
| "dependencies": { | ||
| "@agentic-kit/ollama": "^1.0.3", | ||
| "@constructive-io/graphql-query": "^3.12.14", | ||
| "@pgpmjs/env": "^2.11.0", | ||
| "@pgpmjs/logger": "^2.1.0", | ||
| "graphql-request": "^7.1.2" | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit tests are invoking the handler with legacy param names (e.g.
table_name,record_id,content_field) butfunctions/rag-embedding/handler.tscurrently requires the trigger payload shape (table,schema,id,chunks_table, etc.). As written, these tests will fail early with "Missing required params". Update the test inputs (and mocked GraphQL responses) to match the handler’s expected payload, or add a backward-compatible param mapping in the handler.