Package: generative
Build cross-modal and multi-modal applications on the cloudJina is a framework that empowers anyone to build cross-modal and multi-modal[*]applications on the cloud. It uplifts a PoC into a production-ready service. Jina handles the infrastructure complexity, making advanced solution engineering and cloud-native technologies accessible to every developer.[*]Example cross-modal application:DALL·E Flow; example multi-modal services:CLIP-as-service,Jina Now.Applications built with Jina enjoy the following features out-of-the-box:🌌UniversalBuild applications that deliver fresh insights from multiple data types such as text, image, audio, video, 3D mesh, PDF withJina AI's DocArray.Support all mainstream deep learning frameworks.Polyglot gateway that supports gRPC, Websockets, HTTP, GraphQL protocols with TLS.⚡PerformanceIntuitive design pattern for high-performance microservices.Scaling at ease: set replicas, sharding in one line.Duplex streaming between client and server.Async and non-blocking data processing over dynamic flows.☁️Cloud-nativeSeamless Docker container integration: sharing, exploring, sandboxing, versioning and dependency control viaJina Hub.Fast deployment to Kubernetes, Docker Compose andJina Cloud.Full observability via Prometheus and Grafana.🍱EcosystemImproved engineering efficiency thanks to the Jina AI ecosystem, so you can focus on innovating with the data applications you build.DocumentationInstallpipinstalljinaMore install options can be found in the docs.Get StartedBasic ConceptsDocument, Executor and Flow are three fundamental concepts in Jina.Documentis the fundamental data structure.Executoris a Python class with functions that use Documents as IO.Flowties Executors together into a pipeline and exposes it with an API gateway.The full glossary is explained here.Hello world exampleLeveraging these three concepts, let's look at a simple example below:fromjinaimportDocumentArray,Executor,Flow,requestsclassMyExec(Executor):@requestsasyncdefadd_text(self,docs:DocumentArray,**kwargs):fordindocs:d.text+='hello, world!'f=Flow().add(uses=MyExec).add(uses=MyExec)withf:r=f.post('/',DocumentArray.empty(2))print(r.texts)The first line imports three concepts we just introduced;MyExecdefines an async functionadd_textthat receivesDocumentArrayfrom network requests and appends"hello, world"to.text;fdefines a Flow streamlined two Executors in a chain;Thewithblock opens the Flow, sends an empty DocumentArray to the Flow, and prints the result.Running it gives you:At the last line we see its output['hello, world!hello, world!', 'hello, world!hello, world!'].While one could use standard Python with the same number of lines and get the same output, Jina accelerates time to market of your application by making it more scalable and cloud-native. Jina also handles the infrastructure complexity in production and other Day-2 operations so that you can focus on the data application itself.Scalability and concurrency at easeThe example above can be refactored into a Python Executor file and a Flow YAML file:toy.ymlexecutor.pyjtype:Flowwith:port:51000protocol:grpcexecutors:-uses:MyExecname:foopy_modules:-executor.py-uses:MyExecname:barpy_modules:-executor.pyfromjinaimportDocumentArray,Executor,requestsclassMyExec(Executor):@requestsasyncdefadd_text(self,docs:DocumentArray,**kwargs):fordindocs:d.text+='hello, world!'Run the following command in the terminal:jinaflow--usestoy.ymlThe server is successfully started, and you can now use a client to query it.fromjinaimportClient,Documentc=Client(host='grpc://0.0.0.0:51000')c.post('/',Document())This simple refactoring allows developers to write an application in the client-server style. The separation of Flow YAML and Executor Python file does not only make the project more maintainable but also brings scalability and concurrency to the next level:The data flow on the server is non-blocking and async. New request is handled immediately when an Executor is free, regardless if previous request is still being processed.Scalability can be easily achieved by the keywordsreplicasandneedsin YAML/Python. Load-balancing is automatically added when necessary to ensure the maximum throughput.toy.ymlFlowchartjtype:Flowwith:port:51000protocol:grpcexecutors:-uses:MyExecname:foopy_modules:-executor.pyreplicas:2-uses:MyExecname:barpy_modules:-executor.pyreplicas:3needs:gateway-needs:[foo,bar]name:bazYou now have an API gateway that supports gRPC (default), Websockets, and HTTP protocols with TLS.The communication between clients and the API gateway is duplex.The API gateway allows you to route request to a specific Executor while other parts of the Flow are still busy, via.post(..., target_executor=...)Seamless Container integrationWithout having to worry about dependencies, you can easily share your Executors with others; or use public/private Executors in your project thanks toJina Hub.To create an Executor:jinahubnewTo push it to Jina Hub:jinahubpush.To use a Hub Executor in your Flow:Docker containerSandboxSourceYAMLuses: jinahub+docker://MyExecutoruses: jinahub+sandbox://MyExecutoruses: jinahub://MyExecutorPython.add(uses='jinahub+docker://MyExecutor').add(uses='jinahub+sandbox://MyExecutor').add(uses='jinahub://MyExecutor')Behind this smooth experience is advanced management of Executors:Automated builds on the cloudStore, deploy, and deliver Executors cost-efficiently;Automatically resolve version conflicts and dependencies;Instant delivery of any Executor via Sandbox without pulling anything to local.Fast-lane to cloud-nativeUsing Kubernetes becomes easy:jinaexportkubernetesflow.yml./my-k8s
kubectlapply-R-fmy-k8sUsing Docker Compose becomes easy:jinaexportdocker-composeflow.ymldocker-compose.yml
docker-composeupUsing Prometheus becomes easy:fromjinaimportExecutor,requests,DocumentArrayclassMyExec(Executor):@requestsdefencode(self,docs:DocumentArray,**kwargs):withself.monitor('preprocessing_seconds','Time preprocessing the requests'):docs.tensors=preprocessing(docs)withself.monitor('model_inference_seconds','Time doing inference the requests'):docs.embedding=model_inference(docs.tensors)Using Grafana becomes easy, justdownload this JSONand import it into Grafana:What cloud-native technology is still challenging to you?Tell us, we will handle the complexity and make it easy for you.SupportJoin ourSlack communityand chat with other community members about ideas.Join ourEngineering All Handsmeet-up to discuss your use case and learn Jina's new features.When?The second Tuesday of every monthWhere?Zoom (see our public events calendar/.ical)
andlive stream on YouTubeSubscribe to the latest video tutorials on ourYouTube channelJoin UsJina is backed byJina AIand licensed underApache-2.0.We are actively hiringAI engineers, solution engineers to build the next neural search ecosystem in open source.