### Example Morphik AI Server Startup Output Source: https://www.morphik.ai/docs/getting-started This snippet shows the expected console output when the Morphik AI server successfully starts. It confirms the server process is running, application startup is complete, and provides the local address and port for access. ```text INFO: Started server process [15169] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://localhost:8000 (Press CTRL+C to quit) ``` -------------------------------- ### Launch Morphik AI Server with UV Source: https://www.morphik.ai/docs/getting-started After initial setup, this command starts the Morphik AI server using `uv`. It's used for subsequent launches once the environment is configured, making the server accessible via HTTP. ```bash uv run start_server.py ``` -------------------------------- ### Start and Enable PostgreSQL Service on Ubuntu/Debian Source: https://www.morphik.ai/docs/getting-started Starts the PostgreSQL service immediately and configures it to start automatically on boot using systemctl on Ubuntu or Debian. This ensures the database is always running. ```bash sudo systemctl start postgresql sudo systemctl enable postgresql ``` -------------------------------- ### Launch Morphik AI Docker with Ollama Profile Source: https://www.morphik.ai/docs/getting-started This command starts the Morphik AI Docker setup, specifically activating the `ollama` profile. It builds the necessary images and runs the containers in detached mode, enabling local AI models via Ollama. ```bash docker compose --profile ollama up --build -d ``` -------------------------------- ### Start PostgreSQL Service on macOS Source: https://www.morphik.ai/docs/getting-started Starts the PostgreSQL service (version 14) on macOS using Homebrew services, ensuring the database server is running and accessible. ```bash brew services start postgresql@14 ``` -------------------------------- ### Install Morphik AI Docker with Pre-built Image Source: https://www.morphik.ai/docs/getting-started This command downloads and executes an interactive script to set up Morphik AI using Docker Compose with a pre-built image. It checks for Docker, handles `.env` creation, and starts all necessary services. ```bash curl -sSL https://raw.githubusercontent.com/morphik-org/morphik-core/main/install_docker.sh | bash ``` -------------------------------- ### Ingest and Query File with Morphik Python SDK Source: https://www.morphik.ai/docs/getting-started Example Python code demonstrating how to initialize the Morphik client, ingest a PDF file, wait for its completion, and then query the ingested document. This showcases basic interaction with the Morphik API via the SDK. ```Python from morphik import Morphik # Initialize the Morphik client morphik = Morphik(uri="your-morphik-uri") # Ingest a file doc = morphik.ingest_file(file_path="super/complex/file.pdf") doc.wait_for_completion() # Query the file response = morphik.query(query="What percentage of Morphik users are building something cool?") print(response) # Responds with 100% :) ``` -------------------------------- ### Manage Ollama for Local Models Source: https://www.morphik.ai/docs/getting-started Provides commands for installing Ollama on different operating systems, starting its service, and pulling specific language models like Llama3.2 for local inference. Ollama enables running AI models without cloud providers. ```bash brew install ollama ``` ```bash curl -fsSL https://ollama.com/install.sh | sh ``` ```bash ollama serve ``` ```bash ollama pull llama3.2 ``` -------------------------------- ### Prepare Installer Script for Execution Source: https://www.morphik.ai/docs/getting-started Grants execute permissions to the `install_and_start.sh` script. This is a prerequisite before running the main installation and startup script. ```bash chmod +x install_and_start.sh ``` -------------------------------- ### Incomplete Async Bulk Document Ingestion Setup Source: https://www.morphik.ai/docs/python-sdk/users This snippet appears to be the beginning of an asynchronous bulk document ingestion example, setting up the `Morphik` client and `Path` module. However, the code block is incomplete and does not contain a full function or usage example for asynchronous ingestion. ```Python from morphik import Morphik from pathlib import Path db = Morphik() ``` -------------------------------- ### Python Asynchronous Example: Morphik SDK Initialization Source: https://www.morphik.ai/docs/python-sdk/update_document_metadata Shows the initial setup for an asynchronous operation using the Morphik SDK, including importing the library and initializing the client. ```Python from morphik import Morphik db = Morphik() ``` -------------------------------- ### Run Morphik AI Initial Installer Script Source: https://www.morphik.ai/docs/getting-started This command executes the main installation script for Morphik AI. It sets up a virtual environment, installs dependencies like `colpali-engine` and `llama-cpp-python`, and prepares the server for its first launch. ```bash ./install_and_start.sh ``` -------------------------------- ### Synchronous Customer Support Application Example with User Scopes Source: https://www.morphik.ai/docs/python-sdk/users Illustrates a practical application of user scoping in a synchronous customer support scenario. It demonstrates how to sign in as a specific customer, list their documents, and get personalized answers based solely on their data, optionally applying filters. ```python from morphik import Morphik db = Morphik("morphik://owner_id:token@api.morphik.ai") def process_customer_request(customer_id, query): # Sign in as the specific customer customer_scope = db.signin(customer_id) # List the customer's documents documents = customer_scope.list_documents() print(f"Customer {customer_id} has {len(documents)} documents") # Get personalized answer based only on this customer's documents response = customer_scope.query( query, filters={"type": "support_case"}, temperature=0.3 ) return response.completion ``` -------------------------------- ### Make API Request with cURL Source: https://www.morphik.ai/docs/getting-started Illustrates how to make a POST request to the Morphik API using cURL. This example includes setting the Authorization header with a bearer token, specifying the accept and content-type headers, and sending an empty JSON body. ```Shell curl -X 'POST' 'https://api.morphik.ai/documents?skip=0&limit=10000' \ -H "Authorization: Bearer " -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{}' ``` -------------------------------- ### Install PostgreSQL on Ubuntu/Debian Source: https://www.morphik.ai/docs/getting-started Updates package lists and installs PostgreSQL (recommended version 14) and its contrib modules on Ubuntu or Debian systems using apt. This sets up the core database server. ```bash sudo apt update sudo apt install postgresql postgresql-contrib ``` -------------------------------- ### Verify PostgreSQL Installation Source: https://www.morphik.ai/docs/getting-started Executes a SQL query using the `psql` command-line tool to check the installed PostgreSQL version. This command verifies that the PostgreSQL server is running and accessible. ```bash psql -U postgres -c "SELECT version();" ``` -------------------------------- ### API Reference: List Files For Connector Source: https://www.morphik.ai/docs/api-reference/ee--connectors/list-files-for-connector Comprehensive documentation for the GET /ee/connectors/{connector_type}/files endpoint, detailing request parameters (headers, path, query) and providing an example of the successful JSON response structure. ```APIDOC GET /ee/connectors/{connector_type}/files Headers: authorization: string Path Parameters: connector_type: string (required) Query Parameters: path: string | null page_token: string | null q_filter: string | null page_size: integer (default: 100) Response: Status: 200, 422 Content-Type: application/json Description: Successful Response Type: object ``` ```json { "files": [ { "id": "", "name": "", "is_folder": false, "mime_type": "", "size": 123, "modified_date": "" } ], "next_page_token": "" } ``` -------------------------------- ### Asynchronous Python example for `create_cache` Source: https://www.morphik.ai/docs/python-sdk/create_cache Provides an asynchronous Python example demonstrating how to initialize the `Morphik` client and use `create_cache` with filters. Note: The provided example is incomplete. ```Python from morphik import Morphik db = Morphik() # This will include both: # 1. Any documents with category="programming" ``` -------------------------------- ### Install Node.js on Windows using Chocolatey Source: https://www.morphik.ai/docs/using-morphik/morphik-ui This PowerShell script demonstrates how to install Chocolatey (a package manager for Windows) and then use it to install Node.js. It requires running PowerShell as an administrator to execute the installation commands. ```powershell # Install Chocolatey if you don't have it (run in PowerShell as Admin) Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) # Install Node.js choco install nodejs ``` -------------------------------- ### Asynchronous Graph Creation with Custom Entity Extraction Examples (Python) Source: https://www.morphik.ai/docs/python-sdk/create_graph This example illustrates how to asynchronously create a graph and customize the entity extraction process by providing specific `EntityExtractionExample` instances. This allows guiding the model on what types of entities to extract, without modifying the prompt template itself. ```Python from morphik.models import EntityExtractionPromptOverride, EntityExtractionExample, GraphPromptOverrides async with AsyncMorphik() as db: # Example with only entity extraction examples graph = await db.create_graph( name="medical_graph", filters={"category": "medical"}, prompt_overrides=GraphPromptOverrides( entity_extraction=EntityExtractionPromptOverride( examples=[ EntityExtractionExample(label="Insulin", type="MEDICATION"), EntityExtractionExample(label="Diabetes", type="CONDITION") ] ) ) ) ``` -------------------------------- ### Perform Folder Operations: Get, Ingest, List, Retrieve, Query Source: https://www.morphik.ai/docs/python-sdk/folders Demonstrates common operations on a Morphik folder object, including getting an existing folder, ingesting text content, listing documents, retrieving document chunks, and performing a contextual query. Examples are provided for both synchronous and asynchronous execution. ```Python # Get a folder folder = db.get_folder("marketing_docs") # Ingest a document into this folder doc = folder.ingest_text("New marketing strategy for Q3", filename="strategy_q3.txt", metadata={"department": "marketing", "quarter": "Q3"}) # Retrieve documents only from this folder marketing_docs = folder.list_documents() # Search documents only within this folder results = folder.retrieve_chunks("marketing strategy") # Query within the folder context response = folder.query("What is our Q3 marketing strategy?") ``` ```Python # Get a folder folder = db.get_folder("marketing_docs") # Ingest a document into this folder doc = await folder.ingest_text("New marketing strategy for Q3", filename="strategy_q3.txt", metadata={"department": "marketing", "quarter": "Q3"}) # Retrieve documents only from this folder marketing_docs = await folder.list_documents() # Search documents only within this folder results = await folder.retrieve_chunks("marketing strategy") # Query within the folder context response = await folder.query("What is our Q3 marketing strategy?") ``` -------------------------------- ### Asynchronous Customer Project Query with AsyncMorphik Source: https://www.morphik.ai/docs/python-sdk/users This Python snippet illustrates how to perform asynchronous customer-scoped queries using `AsyncMorphik`. It defines an `async` function that retrieves a project folder, signs in a customer, and executes an asynchronous query. The example includes the necessary `asyncio` setup to run the asynchronous function, demonstrating the `await` keyword for non-blocking operations. ```Python from morphik import AsyncMorphik async def handle_customer_request(customer_id, project_name, query): async with AsyncMorphik() as db: # First, get the project folder project_folder = db.get_folder(project_name) # Then, scope to the specific customer within that project customer_project = project_folder.signin(customer_id) # Generate a response using only this customer's documents # within this specific project response = await customer_project.query( query, filters={"status": "active"}, max_tokens=500 ) return { "customer_id": customer_id, "project": project_name, "query": query, "response": response.completion } # Handle request for a specific customer and project import asyncio async def main(): result = await handle_customer_request( "acme_corp", "website_redesign", "What's our current timeline for the homepage redesign?" ) print(f"Response for {result['customer_id']} on {result['project']}:") print(result['response']) # Run the async function asyncio.run(main()) ``` -------------------------------- ### Verify Node.js and npm Installation Source: https://www.morphik.ai/docs/using-morphik/morphik-ui Checks the installed versions of Node.js and npm to confirm successful installation and readiness for use. This is a crucial step to ensure the development environment is correctly set up. ```bash node -v npm -v ``` -------------------------------- ### Install Node.js on macOS using Homebrew Source: https://www.morphik.ai/docs/using-morphik/morphik-ui This script provides commands to install Homebrew (if not already present) and then use it to install Node.js on a macOS system. Homebrew simplifies package management on macOS, making Node.js installation straightforward. ```bash # Install Homebrew if you don't have it /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Install Node.js brew install node ``` -------------------------------- ### Install Core System Dependencies (Linux) Source: https://www.morphik.ai/docs/getting-started Installs essential system-level dependencies like Poppler utilities, Tesseract OCR, and libmagic development files using apt-get on Debian/Ubuntu systems. These are crucial for document processing capabilities. ```bash sudo apt-get update sudo apt-get install -y poppler-utils tesseract-ocr libmagic-dev ``` -------------------------------- ### Initialize Morphik Client for Document Operations Source: https://www.morphik.ai/docs/python-sdk/update_document_with_text This snippet demonstrates how to import the Morphik client and initialize an instance, which is a prerequisite for performing document update operations like `update_document_with_text`. This setup is common for both synchronous and asynchronous usage examples. ```python from morphik import Morphik db = Morphik() ``` -------------------------------- ### Example Request Body for Create App Source: https://www.morphik.ai/docs/api-reference/enterprise/create-app An example of the JSON request body required for the `POST /ee/create_app` endpoint. This particular example shows an empty JSON object, indicating no specific parameters are needed in the body for this request. ```JSON {} ``` -------------------------------- ### Install Morphik Python SDK Source: https://www.morphik.ai/docs/getting-started Command to install the Morphik Python SDK using pip within the activated virtual environment. This makes the SDK's functionalities available for use in your Python project. ```Shell pip install morphik ``` -------------------------------- ### Install PostgreSQL and pgvector on macOS Source: https://www.morphik.ai/docs/getting-started Installs PostgreSQL version 14 and the pgvector extension using Homebrew on macOS, providing the necessary database and vector search capabilities for Morphik. ```bash brew install postgresql@14 brew install pgvector ``` -------------------------------- ### Get Chat History API Response Example Source: https://www.morphik.ai/docs/api-reference/get-chat-history An example JSON structure for a successful response from the Get Chat History API, illustrating the format of a single user message within the chat history. ```JSON [ { "role": "user", "content": "", "timestamp": "", "agent_data": {} } ] ``` -------------------------------- ### Build and Run Morphik AI Docker from Source Source: https://www.morphik.ai/docs/getting-started This set of commands clones the Morphik AI repository, navigates into it, makes the `start.sh` script executable, and then runs it to build and launch the Docker containers from source code. ```bash git clone https://github.com/morphik-org/morphik-core.git cd morphik-core chmod +x start.sh ./start.sh ``` -------------------------------- ### Example Response Body for Get Document By Filename Source: https://www.morphik.ai/docs/api-reference/get-document-by-filename An example JSON structure representing the metadata of a document returned by the 'Get Document By Filename' API endpoint. It includes fields like external ID, owner, content type, filename, storage information, and access control. ```json { "external_id": "", "owner": {}, "content_type": "", "filename": "", "metadata": {}, "storage_info": {}, "storage_files": [ { "bucket": "", "key": "", "version": 1, "filename": "", "content_type": "", "timestamp": "2023-11-07T05:31:56Z" } ], "system_metadata": {}, "additional_metadata": {}, "access_control": {}, "chunk_ids": [ "" ] } ``` -------------------------------- ### Clone and Navigate Morphik Repository Source: https://www.morphik.ai/docs/getting-started Instructions to clone the `morphik-core` GitHub repository and navigate into its directory. This is the first step to obtain the project's source code. ```bash git clone https://github.com/morphik-org/morphik-core.git ``` ```bash cd morphik-core ``` -------------------------------- ### Get Document API Response JSON Schema Source: https://www.morphik.ai/docs/api-reference/get-document Provides an example JSON structure for the successful response when fetching a document, outlining fields such as external ID, content type, filename, metadata, and storage details. ```JSON { "external_id": "", "owner": {}, "content_type": "", "filename": "", "metadata": {}, "storage_info": {}, "storage_files": [ { "bucket": "", "key": "", "version": 1, "filename": "", "content_type": "", "timestamp": "2023-11-07T05:31:56Z" } ], "system_metadata": {}, "additional_metadata": {}, "access_control": {}, "chunk_ids": [ "" ] } ``` -------------------------------- ### Query Morphik with Python SDK Source: https://www.morphik.ai/docs/getting-started Demonstrates how to use the Morphik Python SDK to query a file. This snippet shows a basic query operation and prints the response received from the Morphik service. ```Python response = morphik.query(query="What percentage of Morphik users are building something cool?") print(response) ``` -------------------------------- ### Update Graph with Custom Entity Resolution (Sync) Source: https://www.morphik.ai/docs/python-sdk/update_graph Demonstrates how to update a graph synchronously using `db.update_graph`. It includes examples for providing custom entity resolution examples and overriding the entity resolution prompt template to guide the AI in resolving entities. ```Python from morphik.models import EntityResolutionPromptOverride, EntityResolutionExample, GraphPromptOverrides # Update with custom entity resolution examples updated_graph = db.update_graph( name="research_graph", additional_documents=["doc_123"], prompt_overrides=GraphPromptOverrides( entity_resolution=EntityResolutionPromptOverride( examples=[ EntityResolutionExample( canonical="Machine Learning", variants=["ML", "machine learning", "AI/ML"] ), EntityResolutionExample( canonical="Natural Language Processing", variants=["NLP", "natural language processing", "text processing"] ) ] ) ) ) # With custom entity resolution prompt template updated_graph = db.update_graph( name="research_graph", additional_filters={"year": "2025"}, prompt_overrides=GraphPromptOverrides( entity_resolution=EntityResolutionPromptOverride( prompt_template="""I have extracted the following entities from the text: {entities_str} Here are examples of how different entity references can be grouped together: {examples_json} Please resolve these entities by identifying which mentions refer to the same entity. Group them together, selecting a canonical/preferred form for each group. Return your resolution in JSON format with the canonical form and all its variants. """, examples=[ EntityResolutionExample( canonical="General AI", variants=["AGI", "General Artificial Intelligence", "General AI"] ) ] ) ) ) ``` -------------------------------- ### Set up RAG pipeline with Morphik Python SDK Source: https://www.morphik.ai/docs/knowledge-base/how-do-i-set-up-rag This code snippet demonstrates how to set up a Retrieval Augmented Generation (RAG) workflow using the Morphik Python SDK. It covers initializing the Morphik client, ingesting a document (e.g., PDF), creating a retrieval cache, and performing a query to retrieve relevant context and generate a response. The example showcases Morphik's unified API for simplified RAG implementation. ```Python from morphik import Morphik # Initialize the client db = Morphik("morphik://owner_id:token@api.morphik.ai") # 1. Ingest a document doc = db.ingest_file("document.pdf") # 2. Create a cache for quick retrieval db.create_cache(name="docs-cache", model="openai_gpt4o", gguf_file="model.gguf", docs=[doc.id]) # 3 & 4. Retrieve and generate with context response = db.query("What topics are covered?", k=4) print(response.text) ``` -------------------------------- ### Create Graph with Custom Entity Extraction Examples (Python) Source: https://www.morphik.ai/docs/python-sdk/create_graph This example illustrates how to guide the entity extraction process by providing specific examples of entities and their types. By using `EntityExtractionExample` within `GraphPromptOverrides`, users can ensure that the AI model focuses on identifying relevant domain-specific entities like 'Insulin' as a 'MEDICATION' or 'Diabetes' as a 'CONDITION'. This enhances the accuracy and relevance of the extracted knowledge graph for specialized domains. ```Python from morphik.models import EntityExtractionPromptOverride, EntityExtractionExample, GraphPromptOverrides # Example with only entity extraction examples graph = db.create_graph( name="medical_graph", filters={"category": "medical"}, prompt_overrides=GraphPromptOverrides( entity_extraction=EntityExtractionPromptOverride( examples=[ EntityExtractionExample(label="Insulin", type="MEDICATION"), EntityExtractionExample(label="Diabetes", type="CONDITION") ] ) ) ) ``` -------------------------------- ### Update Graph with Custom Entity Extraction Examples (Python) Source: https://www.morphik.ai/docs/python-sdk/update_graph This snippet demonstrates how to update a graph in a database by providing specific examples for entity extraction. It shows how to define custom labels and types for entities like "Insulin" (MEDICATION) or "Diabetes" (CONDITION) to guide the extraction process. ```Python updated_graph = await db.update_graph( name="medical_graph", additional_filters={"category": "new_medical_data"}, prompt_overrides=GraphPromptOverrides( entity_extraction=EntityExtractionPromptOverride( examples=[ EntityExtractionExample(label="Insulin", type="MEDICATION"), EntityExtractionExample(label="Diabetes", type="CONDITION"), EntityExtractionExample(label="Heart rate", type="VITAL_SIGN"), EntityExtractionExample(label="Cardiology", type="SPECIALTY") ] ) ) ) ``` -------------------------------- ### Update Graph with Custom Entity Extraction Examples and Template Source: https://www.morphik.ai/docs/python-sdk/update_graph This Python code demonstrates two methods for customizing entity extraction during a graph update. The first part shows how to provide specific `EntityExtractionExample` instances to guide the extraction process for a 'medical_graph'. The second part illustrates overriding the entire prompt template for a 'legal_graph', defining a custom JSON structure for extracted entities and providing examples with properties. ```python from morphik.models import EntityExtractionPromptOverride, EntityExtractionExample, GraphPromptOverrides # Update with custom entity extraction examples updated_graph = db.update_graph( name="medical_graph", additional_filters={"category": "new_medical_data"}, prompt_overrides=GraphPromptOverrides( entity_extraction=EntityExtractionPromptOverride( examples=[ EntityExtractionExample(label="Insulin", type="MEDICATION"), EntityExtractionExample(label="Diabetes", type="CONDITION"), EntityExtractionExample(label="Heart rate", type="VITAL_SIGN"), EntityExtractionExample(label="Cardiology", type="SPECIALTY") ] ) ) ) # With custom entity extraction template updated_graph = db.update_graph( name="legal_graph", additional_documents=["contract1", "contract2"], prompt_overrides=GraphPromptOverrides( entity_extraction=EntityExtractionPromptOverride( prompt_template="""Extract legal entities from the following document: {content} Focus on these types of entities: {examples} Return the extracted entities in JSON format with the following structure: [ {"label": "entity name", "type": "ENTITY_TYPE", "properties": {"key": "value"}} ] """, examples=[ EntityExtractionExample( label="John Smith", type="PERSON", properties={"role": "Plaintiff"} ), EntityExtractionExample( label="Acme Corporation", type="ORGANIZATION", properties={"type": "Corporation"} ), EntityExtractionExample( label="January 15, 2025", type="DATE" ) ] ) ) ) ``` -------------------------------- ### Complete Morphik AI Configuration Example (morphik.toml) Source: https://www.morphik.ai/docs/configuration This comprehensive TOML example demonstrates the full structure of a `morphik.toml` file. It includes API settings, authentication parameters, and definitions for various registered AI models from OpenAI, Azure OpenAI, Anthropic, and Ollama, specifying their respective model names, API bases, and other relevant parameters. ```TOML [api] host = "localhost" # Use "0.0.0.0" for Docker port = 8000 reload = true [auth] jwt_algorithm = "HS256" dev_mode = true dev_entity_id = "dev_user" dev_entity_type = "developer" dev_permissions = ["read", "write", "admin"] [registered_models] # OpenAI models openai_gpt4-1 = { model_name = "gpt-4.1" } openai_gpt4-1-mini = { model_name = "gpt-4.1-mini" } # Azure OpenAI models azure_gpt4 = { model_name = "gpt-4", api_base = "YOUR_AZURE_URL_HERE", api_version = "2023-05-15", deployment_id = "gpt-4-deployment" } azure_gpt35 = { model_name = "gpt-3.5-turbo", api_base = "YOUR_AZURE_URL_HERE", api_version = "2023-05-15", deployment_id = "gpt-35-turbo-deployment" } # Anthropic models claude_opus = { model_name = "claude-3-opus-20240229" } claude_sonnet = { model_name = "claude-3-7-sonnet-latest" } # Ollama models (modify api_base based on your deployment) # - Local Ollama: "http://localhost:11434" (default) # - Morphik in Docker, Ollama local: "http://host.docker.internal:11434" # - Both in Docker: "http://ollama:11434" ollama_qwen_vision = { model_name = "ollama_chat/qwen2.5vl:latest", api_base = "http://localhost:11434", vision = true } ollama_llama_vision = { model_name = "ollama_chat/llama3.2-vision", api_base = "http://localhost:11434", vision = true } ollama_embedding = { model_name = "ollama/nomic-embed-text", api_base = "http://localhost:11434" } ``` -------------------------------- ### Example JSON Response for List Graphs API Source: https://www.morphik.ai/docs/api-reference/list-graphs Provides a sample JSON structure returned by the GET /graphs endpoint, illustrating the format of graph, entity, and relationship objects, along with metadata and access control details. ```json [ { "id": "", "name": "", "entities": [ { "id": "", "label": "", "type": "", "properties": {}, "document_ids": [ "" ], "chunk_sources": {} } ], "relationships": [ { "id": "", "source_id": "", "target_id": "", "type": "", "document_ids": [ "" ], "chunk_sources": {} } ], "metadata": {}, "system_metadata": {}, "document_ids": [ "" ], "filters": {}, "created_at": "2023-11-07T05:31:56Z", "updated_at": "2023-11-07T05:31:56Z", "owner": {}, "access_control": {} } ] ``` -------------------------------- ### Install Node.js Dependencies Source: https://www.morphik.ai/docs/using-morphik/morphik-ui Installs all required Node.js package dependencies listed in the 'package.json' file for the current project. This command fetches and sets up all necessary libraries for the UI component to run. ```bash npm i ``` -------------------------------- ### Initialize Morphik Client Synchronously Source: https://www.morphik.ai/docs/python-sdk/morphik Demonstrates how to initialize the Morphik client in synchronous mode. Examples include initializing without authentication and with authentication using a connection string containing owner ID and token. ```Python from morphik import Morphik # Without authentication db = Morphik() # With authentication db = Morphik("morphik://owner_id:token@api.morphik.ai") ``` -------------------------------- ### Example Output of UI Development Server Source: https://www.morphik.ai/docs/using-morphik/morphik-ui Shows the expected console output when successfully running the Morphik UI in development mode. It indicates the local server address (e.g., http://localhost:3000) and confirms that the application is ready. ```console (base) arnav@Arnavs-MacBook-Air ui-component % npm run dev > @morphik/ui@0.1.0 dev > next dev ▲ Next.js 14.2.26 - Local: http://localhost:3000 ✓ Starting... ✓ Ready in 1560ms ``` -------------------------------- ### List Model Configurations API Endpoint Source: https://www.morphik.ai/docs/api-reference/model-config/list-model-configs Documents the GET /model-config API endpoint, which retrieves all model configurations for the authenticated user and app. It requires an 'authorization' header and returns an array of ModelConfigResponse objects on success, along with an example JSON payload. ```APIDOC GET /model-config Headers: authorization: string Response: 200 application/json: Successful Response Type: ModelConfigResponse[] (object array) 422: Unprocessable Entity ``` ```JSON [ { "id": "", "provider": "", "config_data": {}, "created_at": "2023-11-07T05:31:56Z", "updated_at": "2023-11-07T05:31:56Z" } ] ``` -------------------------------- ### Initialize PostgreSQL Database Schema Source: https://www.morphik.ai/docs/getting-started Executes the `init.sql` script to initialize the `morphik` database schema for the `postgres` user. This step is often necessary to resolve database initialization issues within Docker environments. ```bash psql -U postgres -d morphik -a -f init.sql ``` -------------------------------- ### Basic TOML Configuration Section Source: https://www.morphik.ai/docs/configuration Illustrates the fundamental structure of a section within the `morphik.toml` configuration file, showing how to define key-value pairs under a named section. ```TOML [section_name] setting1 = "value1" setting2 = 123 ``` -------------------------------- ### Combine Folder and User Scoping for Enterprise Knowledge Management Source: https://www.morphik.ai/docs/concepts/user-folder-scoping This example showcases how to combine both folder and user scopes for complex enterprise setups. It allows organizing data by department (e.g., marketing, engineering) and then further by individual users within those departments, providing granular control over knowledge management. ```python # Marketing department marketing = db.get_folder("marketing") # Individual marketers' workspaces alice_marketing = marketing.signin("alice") bob_marketing = marketing.signin("bob") # Engineering department engineering = db.get_folder("engineering") # Individual engineers' workspaces charlie_engineering = engineering.signin("charlie") dave_engineering = engineering.signin("dave") ``` -------------------------------- ### Initialize Morphik Python Client Source: https://www.morphik.ai/docs/python-sdk/update_document_with_file A basic Python example demonstrating how to import the Morphik library and initialize the `Morphik` client object, which is the entry point for interacting with the Morphik API. ```Python from morphik import Morphik db = Morphik() ``` -------------------------------- ### Define Morphik Client Constructor Parameters Source: https://www.morphik.ai/docs/python-sdk/morphik API documentation for initializing the Morphik and AsyncMorphik clients. It details the 'uri', 'timeout', and 'is_local' parameters, including their types, default values, and purpose for connecting to the Morphik service. ```APIDOC Morphik Client Constructor: Morphik(uri: Optional[str] = None, timeout: int = 30, is_local: bool = False) AsyncMorphik(uri: Optional[str] = None, timeout: int = 30, is_local: bool = False) Parameters: uri (str, optional): Morphik URI in format “morphik://:@”. If not provided, connects to http://localhost:8000 without authentication. timeout (int, optional): Request timeout in seconds. Defaults to 30. is_local (bool, optional): Whether connecting to local development server. Defaults to False. ``` -------------------------------- ### Synchronous Python example for `create_cache` Source: https://www.morphik.ai/docs/python-sdk/create_cache Provides a synchronous Python example demonstrating how to initialize the `Morphik` client and use `create_cache` with both filters and explicit document IDs to build a cache. ```Python from morphik import Morphik db = Morphik() # This will include both: # 1. Any documents with category="programming" # 2. The specific documents "doc1" and "doc2" (regardless of their category) cache = db.create_cache( name="programming_cache", model="llama2", gguf_file="llama-2-7b-chat.Q4_K_M.gguf", filters={"category": "programming"}, docs=["doc1", "doc2"] ) ``` -------------------------------- ### Manage Project Data with Asynchronous Morphik Folders Source: https://www.morphik.ai/docs/python-sdk/folders This snippet illustrates the asynchronous approach to managing project data using `AsyncMorphik`. It mirrors the synchronous example by showing how to initialize an async Morphik instance, create project folders, asynchronously ingest documentation, perform scoped queries, and create knowledge graphs. It requires an `asyncio` context and the `morphik` library. ```Python from morphik import AsyncMorphik from pathlib import Path async with AsyncMorphik() as db: # Create folders for different projects project_a = db.create_folder("project_a") project_b = db.create_folder("project_b") # Ingest project documentation into respective folders await project_a.ingest_directory(Path("/path/to/project_a_docs"), recursive=True, metadata={"project": "Project A"}) await project_b.ingest_directory(Path("/path/to/project_b_docs"), recursive=True, metadata={"project": "Project B"}) # Query is scoped to just Project A documents project_a_response = await project_a.query("What are the key milestones for this project?") # Query is scoped to just Project B documents project_b_response = await project_b.query("What are the technical requirements?") # Create project-specific knowledge graphs await project_a.create_graph("project_a_graph") await project_b.create_graph("project_b_graph") ``` -------------------------------- ### GET Get Graph Visualization API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-graph-visualization API endpoint, used to retrieve data for visualizing a graph. ```APIDOC GET Get Graph Visualization ``` -------------------------------- ### View Docker Compose Service Logs Source: https://www.morphik.ai/docs/getting-started Commands to view logs for all Docker Compose services or specific services like Morphik, PostgreSQL, and Ollama. These are useful for debugging service startup or runtime issues. ```Shell # View all logs docker compose logs # View specific service logs docker compose logs morphik docker compose logs postgres docker compose logs ollama ``` -------------------------------- ### GET Get Graph API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-graph API endpoint, used to retrieve a specific graph structure by its identifier. ```APIDOC GET Get Graph ``` -------------------------------- ### Install Node.js LTS using NVM Source: https://www.morphik.ai/docs/using-morphik/morphik-ui Installs the latest Long Term Support (LTS) version of Node.js using Node Version Manager (NVM). NVM allows managing multiple Node.js versions on a single machine. ```bash nvm install --lts ``` -------------------------------- ### GET Get Folder API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-folder API endpoint, used to retrieve details of a specific folder by its identifier. ```APIDOC GET Get Folder ``` -------------------------------- ### GET Get Cache API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-cache API endpoint, used to retrieve the contents or details of a specific cache. ```APIDOC GET Get Cache ``` -------------------------------- ### Example: Response for Create New Morphik Application Source: https://www.morphik.ai/docs/api-reference/management-api Illustrates the expected JSON response body upon successful creation (HTTP 201) of a new Morphik application. It includes the application ID, name, a Morphik URI for interaction, and the provisioning status, indicating the application is ready for use. ```JSON { "app_id": "app_abc123xyz789", "app_name": "My New Marketing App", "morphik_uri": "morphik://{name}:{token}@your-company.morphik.ai", "status": "Provisioned" } ``` -------------------------------- ### GET Get Usage Stats API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-usage-stats API endpoint, providing statistical data on system usage. ```APIDOC GET Get Usage Stats ``` -------------------------------- ### GET Get Document API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-document API endpoint, used to retrieve a single document by its unique identifier. ```APIDOC GET Get Document ``` -------------------------------- ### Perform Simple Synchronous Agent Query with Morphik Source: https://www.morphik.ai/docs/python-sdk/agent_query Demonstrates how to perform a basic informational query using the synchronous Morphik agent. It shows how to initialize the Morphik client, execute a query, and then process the 'response', 'tool_history', 'display_objects', and 'sources' returned by the agent. ```Python from morphik import Morphik db = Morphik() # Simple informational query result = db.agent_query("What are the main trends in our Q3 sales data?") print("Agent Response:") print(result["response"]) # Check what tools were used print("\nTools Used:") for tool in result["tool_history"]: print(f"- {tool['tool_name']}: {tool['tool_args']}") # Display structured content print("\nDisplay Objects:") for obj in result["display_objects"]: if obj["type"] == "text": print(f"Text from {obj['source']}: {obj['content'][:100]}...") elif obj["type"] == "image": print(f"Image from {obj['source']}: {obj['caption']}") # Check sources print("\nSources:") for source in result["sources"]: print(f"- {source['documentName']} (ID: {source['sourceId']})") ``` -------------------------------- ### GET Get Recent Usage API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-recent-usage API endpoint, providing data on recent system usage activities. ```APIDOC GET Get Recent Usage ``` -------------------------------- ### GET Get Document Download Url API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-document-download-url API endpoint, which generates a temporary URL for downloading a document. ```APIDOC GET Get Document Download Url ``` -------------------------------- ### Query Completion API 200 Response Example Source: https://www.morphik.ai/docs/api-reference/query-completion An example JSON structure for a successful 200 OK response from the Query Completion API, showing the expected fields like completion, usage, finish reason, sources, and metadata. ```JSON { "completion": "", "usage": {}, "finish_reason": "", "sources": [], "metadata": {} } ``` -------------------------------- ### GET Get Document By Filename API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-document-by-filename API endpoint, allowing retrieval of a document using its filename as an identifier. ```APIDOC GET Get Document By Filename ``` -------------------------------- ### Create Morphik Database and User on Ubuntu/Debian Source: https://www.morphik.ai/docs/getting-started Creates a new PostgreSQL database named "morphik" and a superuser named "postgres" as the postgres user. These credentials are used by the Morphik application to connect to the database. ```bash sudo -u postgres createdb morphik sudo -u postgres createuser -s postgres ``` -------------------------------- ### GET Get Document Status API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-document-status API endpoint, which provides the current processing status of a specific document. ```APIDOC GET Get Document Status ``` -------------------------------- ### Download NLTK Data for Python Environment Source: https://www.morphik.ai/docs/getting-started Downloads specific NLTK (Natural Language Toolkit) data packages, `averaged_perceptron_tagger` and `punkt`, which are required for certain text processing functionalities within the Python environment. ```python python -m nltk.downloader averaged_perceptron_tagger punkt ``` -------------------------------- ### Install pgvector on Ubuntu/Debian Source: https://www.morphik.ai/docs/getting-started Installs the pgvector extension specifically for PostgreSQL 14 on Ubuntu or Debian systems using apt. This enables vector storage and similarity search capabilities. ```bash sudo apt install postgresql-14-pgvector ``` -------------------------------- ### Example Configuration for Mixing AI Models Source: https://www.morphik.ai/docs/configuration This snippet illustrates how to configure different AI models for specific tasks within the Morphik AI system, enabling optimized resource utilization. It demonstrates assigning a Llama vision model for image analysis, a Claude Sonnet model for rules processing, and a Qwen vision model for general completion, showcasing the flexibility of model integration. ```TOML [parser.vision] model = "ollama_llama_vision" # Use Llama vision model for image analysis [rules] model = "claude_sonnet" # Use Claude Sonnet for rules processing [completion] model = "ollama_qwen_vision" # Use Qwen vision model for general completion ``` -------------------------------- ### GET Get Chat History API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-chat-history API endpoint, which retrieves the historical conversation data for a specific chat session. ```APIDOC GET Get Chat History ``` -------------------------------- ### Strategic Competitive Analysis using Agent Query Source: https://www.morphik.ai/docs/cookbooks/agent-workflows Illustrates how an agent can combine multiple data sources (product documentation, market research, knowledge graph) for strategic insights. It identifies gaps, opportunities, and recommends strategic priorities, also showing how to extract recommendations from `display_objects`. ```Python competitive_analysis = db.agent_query(""" Analyze our product documentation and market research reports. Compare our features against competitor data in the knowledge graph. Identify gaps in our offering and opportunities for differentiation. Calculate market share implications and recommend strategic priorities. """) print("Competitive Analysis:") print(competitive_analysis["response"]) # Extract strategic recommendations for obj in competitive_analysis["display_objects"]: if "recommendation" in obj["content"].lower(): print("\nStrategic Recommendations:") print(obj["content"]) ``` -------------------------------- ### Create and Access Morphik Folders (Synchronous) Source: https://www.morphik.ai/docs/python-sdk/folders Demonstrates how to initialize the Morphik client and then synchronously create a new folder or access an existing one. This method is suitable for blocking operations where immediate results are required. ```Python from morphik import Morphik db = Morphik() # Create a new folder folder = db.create_folder("marketing_docs") # Access an existing folder folder = db.get_folder("marketing_docs") ``` -------------------------------- ### GET Get Document Chat History API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /document/get-document-chat-history API endpoint, used to retrieve chat history related to a specific document. ```APIDOC GET Get Document Chat History ``` -------------------------------- ### GET Get Available Models For Selection API Endpoint Source: https://www.morphik.ai/docs/api-reference/list-documents Documents the GET /get-available-models-for-selection API endpoint, providing a list of models specifically curated for user selection. ```APIDOC GET Get Available Models For Selection ``` -------------------------------- ### Create Morphik Database and User on macOS Source: https://www.morphik.ai/docs/getting-started Creates a new PostgreSQL database named "morphik" and a superuser named "postgres". These credentials are used by the Morphik application to connect to the database. ```bash createdb morphik createuser -s postgres ```