repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | [Elasticsearch](https://www.elastic.co/) is a distributed, RESTful search and analytics engine that can efficiently store and search vector data using dense vectors and k-NN search. |
| #2 | |
| #3 | ### Installation |
| #4 | |
| #5 | Elasticsearch support requires additional dependencies. Install them with: |
| #6 | |
| #7 | ```bash |
| #8 | pip install elasticsearch>=8.0.0 |
| #9 | ``` |
| #10 | |
| #11 | ### Usage |
| #12 | |
| #13 | ```python |
| #14 | import os |
| #15 | from mem0 import Memory |
| #16 | |
| #17 | os.environ["OPENAI_API_KEY"] = "sk-xx" |
| #18 | |
| #19 | config = { |
| #20 | "vector_store": { |
| #21 | "provider": "elasticsearch", |
| #22 | "config": { |
| #23 | "collection_name": "mem0", |
| #24 | "host": "localhost", |
| #25 | "port": 9200, |
| #26 | "embedding_model_dims": 1536 |
| #27 | } |
| #28 | } |
| #29 | } |
| #30 | |
| #31 | m = Memory.from_config(config) |
| #32 | messages = [ |
| #33 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #34 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #35 | {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."}, |
| #36 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #37 | ] |
| #38 | m.add(messages, user_id="alice", metadata={"category": "movies"}) |
| #39 | ``` |
| #40 | |
| #41 | ### Config |
| #42 | |
| #43 | Here are the parameters available for configuring Elasticsearch: |
| #44 | |
| #45 | | Parameter | Description | Default Value | |
| #46 | | ---------------------- | -------------------------------------------------- | ------------- | |
| #47 | | `collection_name` | The name of the index to store the vectors | `mem0` | |
| #48 | | `embedding_model_dims` | Dimensions of the embedding model | `1536` | |
| #49 | | `host` | The host where the Elasticsearch server is running | `localhost` | |
| #50 | | `port` | The port where the Elasticsearch server is running | `9200` | |
| #51 | | `cloud_id` | Cloud ID for Elastic Cloud deployment | `None` | |
| #52 | | `api_key` | API key for authentication | `None` | |
| #53 | | `user` | Username for basic authentication | `None` | |
| #54 | | `password` | Password for basic authentication | `None` | |
| #55 | | `verify_certs` | Whether to verify SSL certificates | `True` | |
| #56 | | `auto_create_index` | Whether to automatically create the index | `True` | |
| #57 | | `custom_search_query` | Function returning a custom search query | `None` | |
| #58 | | `headers` | Custom headers to include in requests | `None` | |
| #59 | |
| #60 | ### Features |
| #61 | |
| #62 | - Efficient vector search using Elasticsearch's native k-NN search |
| #63 | - Support for both local and cloud deployments (Elastic Cloud) |
| #64 | - Multiple authentication methods (Basic Auth, API Key) |
| #65 | - Automatic index creation with optimized mappings for vector search |
| #66 | - Memory isolation through payload filtering |
| #67 | - Custom search query function to customize the search query |
| #68 | |
| #69 | ### Custom Search Query |
| #70 | |
| #71 | The `custom_search_query` parameter allows you to customize the search query when `Memory.search` is called. |
| #72 | |
| #73 | __Example__ |
| #74 | ```python |
| #75 | import os |
| #76 | from typing import List, Optional, Dict |
| #77 | from mem0 import Memory |
| #78 | |
| #79 | def custom_search_query(query: List[float], limit: int, filters: Optional[Dict]) -> Dict: |
| #80 | return { |
| #81 | "knn": { |
| #82 | "field": "vector", |
| #83 | "query_vector": query, |
| #84 | "k": limit, |
| #85 | "num_candidates": limit * 2 |
| #86 | } |
| #87 | } |
| #88 | |
| #89 | os.environ["OPENAI_API_KEY"] = "sk-xx" |
| #90 | |
| #91 | config = { |
| #92 | "vector_store": { |
| #93 | "provider": "elasticsearch", |
| #94 | "config": { |
| #95 | "collection_name": "mem0", |
| #96 | "host": "localhost", |
| #97 | "port": 9200, |
| #98 | "embedding_model_dims": 1536, |
| #99 | "custom_search_query": custom_search_query |
| #100 | } |
| #101 | } |
| #102 | } |
| #103 | ``` |
| #104 | It should be a function that takes the following parameters: |
| #105 | - `query`: a query vector used in `Memory.search` |
| #106 | - `limit`: a number of results used in `Memory.search` |
| #107 | - `filters`: a dictionary of key-value pairs used in `Memory.search`. You can add custom pairs for the custom search query. |
| #108 | |
| #109 | The function should return a query body for the Elasticsearch search API. |