### Install Dependencies Source: https://github.com/jina-ai/examples/blob/master/audio-to-audio-search/README.md Installs necessary system libraries (libsndfile1, ffmpeg) and Python packages from requirements.txt. ```shell sudo apt-get -y update && sudo apt-get install libsndfile1 ffmpeg pip install -r requirements.txt ``` -------------------------------- ### Run Jina Example Docker Image Source: https://github.com/jina-ai/examples/blob/master/example_template.md This command pulls and runs the Docker image for the Jina example project. Ensure Docker is installed and you have sufficient disk space. ```bash docker . ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/jina-ai/examples/blob/master/multires-lyrics-search/README.md This snippet shows how to clone the example repository and install the necessary Python dependencies using pip. It ensures the project environment is set up correctly. ```sh git clone https://github.com/jina-ai/examples cd examples/multires-lyrics-search pip install -r requirements.txt ``` -------------------------------- ### Clone Repository and Install Jina Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences/README.md Clones the example repository and installs Jina along with other required Python libraries using pip. Ensures you have the latest version of the examples and a clean dependency environment. ```sh git clone https://github.com/jina-ai/examples cd examples/wikipedia-sentences pip install -r requirements.txt ``` -------------------------------- ### Clone Repository and Install Dependencies (Shell) Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences-query-while-indexing/README.md Clones the Jina examples repository and installs the necessary Python packages for the Wikipedia sentence search example. ```shell git clone https://github.com/jina-ai/examples cd examples/wikipedia-sentences-query-while-indexing pip install -r requirements.txt ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/jina-ai/examples/blob/master/example_template.md Installs Jina and other required Python libraries using the pip package installer. It reads the dependencies from the 'requirements.txt' file. ```shell pip install -r requirements.txt ``` -------------------------------- ### Example Script for Downloading Models Source: https://github.com/jina-ai/examples/blob/master/example-guidelines.md If your example relies on externally hosted models, create a script named `get_model.sh` (or similar) to download them. This centralizes model acquisition and ensures reproducibility. ```shell #!/bin/bash # Script to download models ``` -------------------------------- ### Clone Repository and Install Dependencies (Shell) Source: https://github.com/jina-ai/examples/blob/master/cross-modal-search/README.md Clones the Jina examples repository and navigates to the cross-modal-search directory. Then, installs required Python packages using pip. ```shell git clone https://github.com/jina-ai/examples cd examples/cross-modal-search pip install -r requirements.txt ``` -------------------------------- ### Start JinaD Server with Docker Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences-query-while-indexing/README.md Starts the JinaD server using Docker, mounting necessary volumes for Docker socket and Jinad logs, and exposing port 8000. This command ensures JinaD can manage other Docker containers and persists its logs. ```bash docker run --add-host host.docker.internal:host-gateway \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /tmp/jinad:/tmp/jinad \ -p 8000:8000 \ --name jinad \ -d jinaai/jina:2.1.0-daemon ``` -------------------------------- ### Clone Jina Examples Repository Source: https://github.com/jina-ai/examples/blob/master/example_template.md Clones the Jina AI examples repository from GitHub to your local machine. This is the first step to access the example files and datasets. ```shell git clone https://github.com/jina-ai/examples ``` -------------------------------- ### Example Script for Downloading Data Source: https://github.com/jina-ai/examples/blob/master/example-guidelines.md Use a shell script named `get_data.sh` to download datasets required for your Jina example. This keeps the project organized and makes it easy to acquire necessary resources. ```shell #!/bin/bash # Script to download datasets ``` -------------------------------- ### Python Project Dependencies Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences/README.md This file (`requirements.txt`) lists all the necessary Python libraries and their specific versions required to run the Jina example. It is used by package managers like pip to install the project's dependencies. ```text jina==3.0.0 transformers==4.10.0 torch==1.9.0 scikit-learn==0.24.2 ``` -------------------------------- ### Basic .dockerignore Example Source: https://github.com/jina-ai/examples/blob/master/example-guidelines.md A `.dockerignore` file works like `.gitignore` but for Docker images. It prevents unnecessary files from being included in the Docker build context, leading to smaller and more efficient images. This example excludes common Jina project artifacts. ```dockerfile # Ignore data directory data/ # Ignore workspace directory workspace/ # Ignore virtual environment directories virtualenv/ venv/ .venv/ * # Ignore directories storing retrieved assets models/ assets/ # Ignore local configuration files .env *.pyc __pycache__/ ``` -------------------------------- ### Stop and Remove Docker Containers Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences-query-while-indexing/README.md Commands to clean up Docker resources by stopping all running containers and then removing all containers, including stopped ones. This is essential for freeing up resources after the example. ```bash docker stop $(docker ps -a -q) docker rm $(docker ps -a -q) ``` -------------------------------- ### Jina Audio to Audio Search Initialization Source: https://github.com/jina-ai/examples/blob/master/audio-to-audio-search/demo.html Initializes variables for the Jina Audio to Audio Search example. 'prev' is likely used for tracking previous states or results. ```javascript var prev = null; ``` -------------------------------- ### Basic .gitignore Example Source: https://github.com/jina-ai/examples/blob/master/example-guidelines.md A `.gitignore` file specifies intentionally untracked files that Git should ignore. This example includes common directories to ignore for Jina projects, such as data, workspace, and virtual environments. ```gitignore # Ignore data directory data/ # Ignore workspace directory workspace/ # Ignore virtual environment directories venv/ .venv/ * # Ignore directories storing retrieved assets models/ assets/ ``` -------------------------------- ### Start RESTful API with Python Source: https://github.com/jina-ai/examples/blob/master/cross-modal-search/README.md Starts a RESTful API service that listens for search requests. This command requires the 'query_restful' target to be specified. ```shell python app.py -t query_restful ``` -------------------------------- ### Specify Jina Version in requirements.txt Source: https://github.com/jina-ai/examples/blob/master/example-guidelines.md To be eligible for listing, your project must specify the Jina version in the `requirements.txt` file. This ensures compatibility and version control for your project. Replace `x.x.x` with the actual semantic version number. ```text jina==x.x.x ``` -------------------------------- ### Data Download Script Source: https://github.com/jina-ai/examples/blob/master/multires-lyrics-search/README.md Shell script to download the Kaggle dataset required for the Jina example. ```bash get_data.sh ``` -------------------------------- ### Query Data via Client Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences-query-while-indexing/README.md Launches the client application to interact with the deployed Jina Query Flow. It prompts the user for a query, sends it to the Flow, and displays the results. ```python python app.py -t client ``` -------------------------------- ### Search for Similar Audio Source: https://github.com/jina-ai/examples/blob/master/audio-to-audio-search/README.md Searches for similar audio clips by generating query clips from indexed audio and matching them. Supports custom segmenter, encoder, and match threshold configurations. ```shell python app.py search ``` ```shell python app.py search -s vad -e vgg -t 0.9 ``` ```shell python app.py search -s time -e clip -t 0.8 ``` -------------------------------- ### Index Audio Tracks Source: https://github.com/jina-ai/examples/blob/master/audio-to-audio-search/README.md Indexes audio tracks located in the default 'data/mp3/index' directory or a custom path specified by the JINA_DATA_FILE environment variable. ```shell python app.py index ``` ```shell export JINA_DATA_FILE= ``` -------------------------------- ### Index Data using Jina App Source: https://github.com/jina-ai/examples/blob/master/example_template.md Executes the Jina application to index data. The '-t index' argument specifies the indexing task. This process prepares the data for searching. ```shell python app.py -t index ``` -------------------------------- ### Shell script to download Kaggle dataset Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences/README.md This shell script (`get_data.sh`) is responsible for downloading a dataset from Kaggle. It uses the `kaggle` CLI tool to fetch the data, which is a prerequisite for running the Jina example. ```bash #!/bin/bash kaggle datasets download -d username/dataset-name -p ./data ``` -------------------------------- ### Run Jina Application Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences-query-while-indexing/README.md Executes the main application script to create and manage Jina Flows. It handles indexing documents, dumping data, and performing rolling updates on the Query Flow. ```python python app.py -t flows ``` -------------------------------- ### Download Lyrics Data with Kaggle API Source: https://github.com/jina-ai/examples/blob/master/multires-lyrics-search/README.md This snippet demonstrates how to download the full lyrics dataset using the Kaggle API. It first installs the kaggle library and then executes a bash script to manage the data download process. ```sh pip install kaggle bash get_data.sh ``` -------------------------------- ### Query Data using Jina App Source: https://github.com/jina-ai/examples/blob/master/example_template.md Executes the Jina application to perform a data query. The '-t query' argument specifies the query task. This allows users to search the indexed data. ```shell python app.py -t query ``` -------------------------------- ### Download Wikipedia Data Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences/README.md Downloads the full Wikipedia dataset for indexing. Requires prior setup of Kaggle API credentials and then executes a shell script to fetch the data. ```sh sh get_data.sh ``` -------------------------------- ### Query Lyrics Data via REST API Source: https://github.com/jina-ai/examples/blob/master/multires-lyrics-search/README.md This snippet shows how to start the REST API for querying the indexed lyrics data and how to send a search request using cURL. The API processes the query, encodes it, and performs a nearest neighbor search to find similar sentences. ```sh python app.py -t query curl --request POST -d '{"parameters": {"top_k": 10}, "data": ["hello world"]}' -H 'Content-Type: application/json' 'http://0.0.0.0:45678/search' ``` -------------------------------- ### Launch Web Interface for Search Source: https://github.com/jina-ai/examples/blob/master/multires-lyrics-search/README.md This command launches a local web server to provide a graphical user interface for the lyrics search application. Users can interact with the search functionality through their web browser. ```sh cd static python -m http.server ``` -------------------------------- ### Jina Gateway and Requirements Source: https://github.com/jina-ai/examples/blob/master/multires-lyrics-search/README.md Python script for the Jina gateway that combines index and query flows, and a requirements file listing necessary Python libraries. ```python app.py ``` ```python requirements.txt ``` -------------------------------- ### Jina Index and Query Flow Configuration Source: https://github.com/jina-ai/examples/blob/master/multires-lyrics-search/README.md Configuration files for Jina's index and query flows, specifying executors for data encoding, chunking, merging, document handling, ranking, and segmentation. ```yaml flows/index.yml ``` ```yaml flows/index.yml ``` ```yaml pods/encode.yml ``` ```yaml pods/chunk.yml ``` ```yaml pods/chunk_merger.yml ``` ```yaml pods/doc.yml ``` ```yaml pods/ranker.yml ``` ```yaml pods/segment.yml ``` -------------------------------- ### Index Data with Jina App Source: https://github.com/jina-ai/examples/blob/master/cross-modal-search/README.md This command demonstrates how to index data using the Jina app. It specifies the task as 'index', sets the number of documents to 8000, configures the request size, and selects the 'f8k' dataset. The request size is set using an environment variable '$request_size'. ```bash python app.py -t index -n 8000 -s $request_size -d 'f8k' ``` -------------------------------- ### MinRanker Class for Relevance Scoring Source: https://github.com/jina-ai/examples/blob/master/multires-lyrics-search/README.md Implementation of the MinRanker class used in Jina flows to calculate relevance scores for matches. ```python flows/executors.py ``` -------------------------------- ### Index Full Flickr 8k Dataset (Shell) Source: https://github.com/jina-ai/examples/blob/master/cross-modal-search/README.md Indexes the complete Flickr 8k dataset, which contains 8000 images and their captions. This process involves downloading the dataset using a provided script and then running the indexing command with dataset and count parameters. ```shell sh get_data.sh python app.py -t index -d f8k -n 8000 ``` -------------------------------- ### POST /search Source: https://github.com/jina-ai/examples/blob/master/cross-modal-search/README.md Initiates a search request to find semantically similar items based on text input. The API returns a specified number of top results. ```APIDOC ## POST /search ### Description This endpoint allows you to perform a search query against the indexed data. You provide a text query, and the API returns the most semantically similar results based on the `top_k` parameter. ### Method POST ### Endpoint `/search` ### Parameters #### Query Parameters - **top_k** (integer) - Required - The number of top similar results to return. #### Request Body - **data** (string array) - Required - An array of text strings to be used as search queries. - **parameters** (object) - Optional - Additional parameters for the search. - **top_k** (integer) - Optional - Overrides the query parameter `top_k` for this specific request. ### Request Example ```json { "parameters": { "top_k": 5 }, "data": [ "a black dog and a spotted dog are fighting" ] } ``` ### Response #### Success Response (200) - **search_results** (object) - Contains the search results. - **matches** (array) - An array of matched items. - **blob** (numpy array) - For image search, contains the matched images. - **text** (string) - For image search, contains captions for the matched images. #### Response Example ```json { "search_results": { "matches": [ { "blob": "...", "text": "..." } ] } } ``` ``` -------------------------------- ### Index Data for Search Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences/README.md Indexes the downloaded Wikipedia dataset using the Jina application. Allows specifying the number of documents to index via the --num_docs or -n flag, with a default of 10000. ```sh python app.py -t index # Or specify number of documents: python app.py -t index -n 50000 ``` -------------------------------- ### Python Gateway Code for Index & Query Flow Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences/README.md This Python script (`app.py`) serves as the gateway for the Jina application, managing both the indexing and querying processes. It orchestrates the flow of documents through different executors, including a transformer for embedding generation and an indexer for storage and retrieval. ```python from jina import Flow def run(): flow = Flow().load_config('config.yml') with flow: flow.post('/index', inputs='data.json', on_done=lambda resp: print(f'Indexed {len(resp.data.docs)} documents.')) flow.post('/search', inputs='query.json', on_done=lambda resp: print(f'Found {len(resp.data.docs)} results.')) if __name__ == '__main__': run() ``` -------------------------------- ### Query Indexed Data Source: https://github.com/jina-ai/examples/blob/master/wikipedia-sentences/README.md Queries the indexed Wikipedia data with a given sentence prompt. Allows specifying the number of top search results using the --top_k or -k flag, with a default of 5. ```sh python app.py -t query # Or specify top_k results: python app.py -t query -k 10 ``` -------------------------------- ### Perform Custom Image Query (Shell) Source: https://github.com/jina-ai/examples/blob/master/cross-modal-search/README.md Enables users to perform a search query using their own image file. The system will find text captions that best match the provided image. ```shell python app.py -t query --query-image PATH_TO_YOUR_IMAGE ``` -------------------------------- ### Perform Custom Text Query (Shell) Source: https://github.com/jina-ai/examples/blob/master/cross-modal-search/README.md Allows users to perform a search query using their own text input. The system will find images that best match the provided text description. ```shell python app.py -t query --query-text "your text" ``` -------------------------------- ### Send Search Request using Curl Source: https://github.com/jina-ai/examples/blob/master/cross-modal-search/README.md Sends a POST request to the local RESTful API endpoint to perform a search. It includes a JSON payload with search parameters and data. ```shell curl --request POST -d '{"parameters":{"top_k": 5}, "data": ["a black dog and a spotted dog are fighting"]}' -H 'Content-Type: application/json' 'http://localhost:45678/search' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.