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: Cohere |
| #3 | description: "Reranking with Cohere" |
| #4 | --- |
| #5 | |
| #6 | Cohere provides enterprise-grade reranking models with excellent multilingual support and production-ready performance. |
| #7 | |
| #8 | ## Models |
| #9 | |
| #10 | Cohere offers several reranking models: |
| #11 | |
| #12 | - **`rerank-english-v3.0`**: Latest English reranker with best performance |
| #13 | - **`rerank-multilingual-v3.0`**: Multilingual support for global applications |
| #14 | - **`rerank-english-v2.0`**: Previous generation English reranker |
| #15 | |
| #16 | ## Installation |
| #17 | |
| #18 | ```bash |
| #19 | pip install cohere |
| #20 | ``` |
| #21 | |
| #22 | ## Configuration |
| #23 | |
| #24 | ```python Python |
| #25 | from mem0 import Memory |
| #26 | |
| #27 | config = { |
| #28 | "vector_store": { |
| #29 | "provider": "chroma", |
| #30 | "config": { |
| #31 | "collection_name": "my_memories", |
| #32 | "path": "./chroma_db" |
| #33 | } |
| #34 | }, |
| #35 | "llm": { |
| #36 | "provider": "openai", |
| #37 | "config": { |
| #38 | "model": "gpt-4.1-nano-2025-04-14" |
| #39 | } |
| #40 | }, |
| #41 | "reranker": { |
| #42 | "provider": "cohere", |
| #43 | "config": { |
| #44 | "model": "rerank-english-v3.0", |
| #45 | "api_key": "your-cohere-api-key", # or set COHERE_API_KEY |
| #46 | "top_k": 5, |
| #47 | "return_documents": False, |
| #48 | "max_chunks_per_doc": None |
| #49 | } |
| #50 | } |
| #51 | } |
| #52 | |
| #53 | memory = Memory.from_config(config) |
| #54 | ``` |
| #55 | |
| #56 | ## Environment Variables |
| #57 | |
| #58 | Set your API key as an environment variable: |
| #59 | |
| #60 | ```bash |
| #61 | export COHERE_API_KEY="your-api-key" |
| #62 | ``` |
| #63 | |
| #64 | ## Usage Example |
| #65 | |
| #66 | ```python Python |
| #67 | import os |
| #68 | from mem0 import Memory |
| #69 | |
| #70 | # Set API key |
| #71 | os.environ["COHERE_API_KEY"] = "your-api-key" |
| #72 | |
| #73 | # Initialize memory with Cohere reranker |
| #74 | config = { |
| #75 | "vector_store": {"provider": "chroma"}, |
| #76 | "llm": {"provider": "openai", "config": {"model": "gpt-4o-mini"}}, |
| #77 | "rerank": { |
| #78 | "provider": "cohere", |
| #79 | "config": { |
| #80 | "model": "rerank-english-v3.0", |
| #81 | "top_k": 3 |
| #82 | } |
| #83 | } |
| #84 | } |
| #85 | |
| #86 | memory = Memory.from_config(config) |
| #87 | |
| #88 | # Add memories |
| #89 | messages = [ |
| #90 | {"role": "user", "content": "I work as a data scientist at Microsoft"}, |
| #91 | {"role": "user", "content": "I specialize in machine learning and NLP"}, |
| #92 | {"role": "user", "content": "I enjoy playing tennis on weekends"} |
| #93 | ] |
| #94 | |
| #95 | memory.add(messages, user_id="bob") |
| #96 | |
| #97 | # Search with reranking |
| #98 | results = memory.search("What is the user's profession?", user_id="bob") |
| #99 | |
| #100 | for result in results['results']: |
| #101 | print(f"Memory: {result['memory']}") |
| #102 | print(f"Vector Score: {result['score']:.3f}") |
| #103 | print(f"Rerank Score: {result['rerank_score']:.3f}") |
| #104 | print() |
| #105 | ``` |
| #106 | |
| #107 | ## Multilingual Support |
| #108 | |
| #109 | For multilingual applications, use the multilingual model: |
| #110 | |
| #111 | ```python Python |
| #112 | config = { |
| #113 | "rerank": { |
| #114 | "provider": "cohere", |
| #115 | "config": { |
| #116 | "model": "rerank-multilingual-v3.0", |
| #117 | "top_k": 5 |
| #118 | } |
| #119 | } |
| #120 | } |
| #121 | ``` |
| #122 | |
| #123 | ## Configuration Parameters |
| #124 | |
| #125 | | Parameter | Description | Type | Default | |
| #126 | | -------------------- | -------------------------------- | ------ | ----------------------- | |
| #127 | | `model` | Cohere rerank model to use | `str` | `"rerank-english-v3.0"` | |
| #128 | | `api_key` | Cohere API key | `str` | `None` | |
| #129 | | `top_k` | Maximum documents to return | `int` | `None` | |
| #130 | | `return_documents` | Whether to return document texts | `bool` | `False` | |
| #131 | | `max_chunks_per_doc` | Maximum chunks per document | `int` | `None` | |
| #132 | |
| #133 | ## Features |
| #134 | |
| #135 | - **High Quality**: Enterprise-grade relevance scoring |
| #136 | - **Multilingual**: Support for 100+ languages |
| #137 | - **Scalable**: Production-ready with high throughput |
| #138 | - **Reliable**: SLA-backed service with 99.9% uptime |
| #139 | |
| #140 | ## Best Practices |
| #141 | |
| #142 | 1. **Model Selection**: Use `rerank-english-v3.0` for English, `rerank-multilingual-v3.0` for other languages |
| #143 | 2. **Batch Processing**: Process multiple queries efficiently |
| #144 | 3. **Error Handling**: Implement retry logic for production systems |
| #145 | 4. **Monitoring**: Track reranking performance and costs |
| #146 |