Skip to content

Conversation

@KoderFPV
Copy link
Owner

Summary

Implement bidirectional synchronization between MongoDB and Weaviate vector database for products with atomic operations and automatic rollback on failure.

Changes

  • Weaviate Products Schema (clients/weaviate/productsSchema.ts): Collection configuration with text2vec-transformers and multi2vec-clip vectorizers, supports custom inference URLs
  • Weaviate Products Model (models/products/weaviateProductsModel.ts): Pure functions for adding/deleting products from Weaviate
  • Product Service (services/product/productService.ts): Coordinates MongoDB and Weaviate sync with atomic transactions
  • API Route Updates: POST/DELETE routes now use productService for coordinated operations
  • Config Service: Added getSnowflakeInferenceUrl() and getOpenClipInferenceUrl() for vectorizer configuration
  • Weaviate Client: Auto-initializes products schema on first connection

Architecture

  • Independent Models: productsModel (MongoDB only) and weaviateProductsModel (Weaviate only) - no cross-imports
  • Service Coordination: productService handles transaction management and rollback
  • Error Handling: Graceful failures with clear error messages and logging

Atomicity Guarantees

  • Create: Product created in MongoDB, synced to Weaviate, or both reverted on failure
  • Delete: Product deleted from MongoDB, synced to Weaviate, or both restored on failure

Testing

  • Unit tests for weaviateProductsModel (insert/delete operations)
  • Integration tests for productService (transaction coordination and rollback scenarios)

Closes #59

🤖 Generated with Claude Code

KoderFPV and others added 6 commits November 20, 2025 18:47
Implement bidirectional synchronization between MongoDB and Weaviate vector database for products:
- Add/delete products from Weaviate when they are created/deleted in MongoDB
- Ensure atomicity: if Weaviate sync fails, MongoDB changes are rolled back
- Complete separation of concerns with independent models and service coordination

Features:
- Weaviate products schema with text2vec-transformers and multi2vec-clip vectorizers
- Support for custom inference URLs via environment variables
- Atomic create and delete operations with automatic rollback on failure
- Comprehensive unit and integration tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…ate to createProduct and deleteProduct

Simplify function names by removing 'WithWeaviate' suffix since Weaviate sync is now part of the standard product operations.
…into collection schema

- Remove buildTextVectorizerConfig and buildImageVectorizerConfig helper functions
- Embed vectorizer configs directly in collection schema for clarity
- Add sourceProperties to text2vec-transformers to vectorize: name, description, category
- multi2vec-clip vectorizes only imageUrl field
- Remove conditional checks for inference URLs (config service will handle errors)
- Update productService.ts to use aliased imports for MongoDB model functions
- Fix function calls to use createProductMongo and deleteProductMongo aliases
- Prevents naming conflicts between exported service functions and imported model functions
- Ensures TypeScript type checker and linter pass without errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add missing inference URL mocks in weaviate.test.ts (getSnowflakeInferenceUrl, getOpenClipInferenceUrl)
- Fix weaviateProductsModel.test.ts: ensure mockFilter.equal returns mockFilter for proper chain
- Fix productService.test.ts: add collection mock to mockDb for restore operation tests
- Update test assertions to use correct aliased mock function names (createProductMongo, deleteProductMongo)
- All 452 unit tests now pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…tsSchema

- Import CollectionConfigCreate from weaviate-client
- Define config variable with proper typing
- Remove unsafe (client.collections as any).create() cast
- Use typed config object for better type safety

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@KoderFPV KoderFPV added the in progress Something is still in progress label Nov 21, 2025
…roductsCollection

Align with codebase convention of letting TypeScript infer return types automatically.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in progress Something is still in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Weaviate integration for product add/delete operations

2 participants