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 | --- |
| #2 | title: Hugging Face |
| #3 | --- |
| #4 | |
| #5 | You can use embedding models from Huggingface to run Mem0 locally. |
| #6 | |
| #7 | ### Usage |
| #8 | |
| #9 | ```python |
| #10 | import os |
| #11 | from mem0 import Memory |
| #12 | |
| #13 | os.environ["OPENAI_API_KEY"] = "your_api_key" # For LLM |
| #14 | |
| #15 | config = { |
| #16 | "embedder": { |
| #17 | "provider": "huggingface", |
| #18 | "config": { |
| #19 | "model": "multi-qa-MiniLM-L6-cos-v1" |
| #20 | } |
| #21 | } |
| #22 | } |
| #23 | |
| #24 | m = Memory.from_config(config) |
| #25 | messages = [ |
| #26 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #27 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #28 | {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| #29 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #30 | ] |
| #31 | m.add(messages, user_id="john") |
| #32 | ``` |
| #33 | |
| #34 | ### Using Text Embeddings Inference (TEI) |
| #35 | |
| #36 | You can also use Hugging Face's Text Embeddings Inference service for faster and more efficient embeddings: |
| #37 | |
| #38 | ```python |
| #39 | import os |
| #40 | from mem0 import Memory |
| #41 | |
| #42 | os.environ["OPENAI_API_KEY"] = "your_api_key" # For LLM |
| #43 | |
| #44 | # Using HuggingFace Text Embeddings Inference API |
| #45 | config = { |
| #46 | "embedder": { |
| #47 | "provider": "huggingface", |
| #48 | "config": { |
| #49 | "huggingface_base_url": "http://localhost:3000/v1" |
| #50 | } |
| #51 | } |
| #52 | } |
| #53 | |
| #54 | m = Memory.from_config(config) |
| #55 | m.add("This text will be embedded using the TEI service.", user_id="john") |
| #56 | ``` |
| #57 | |
| #58 | To run the TEI service, you can use Docker: |
| #59 | |
| #60 | ```bash |
| #61 | docker run -d -p 3000:80 -v huggingfacetei:/data --platform linux/amd64 \ |
| #62 | ghcr.io/huggingface/text-embeddings-inference:cpu-1.6 \ |
| #63 | --model-id BAAI/bge-small-en-v1.5 |
| #64 | ``` |
| #65 | |
| #66 | ### Config |
| #67 | |
| #68 | Here are the parameters available for configuring Huggingface embedder: |
| #69 | |
| #70 | | Parameter | Description | Default Value | |
| #71 | | --- | --- | --- | |
| #72 | | `model` | The name of the model to use | `multi-qa-MiniLM-L6-cos-v1` | |
| #73 | | `embedding_dims` | Dimensions of the embedding model | `selected_model_dimensions` | |
| #74 | | `model_kwargs` | Additional arguments for the model | `None` | |
| #75 | | `huggingface_base_url` | URL to connect to Text Embeddings Inference (TEI) API | `None` | |